How to define a JSON scheme for a map <String, Integer>?

I have json:

{
"itemType": {"food":22,"electrical":2},
"itemCount":{"NA":211}
}

Here itemType and itemCount will be distributed, but not the values ​​inside them (power, NA, electric) that will change, but they will be in the format: Map

How to define Json Schema for such a general structure?

I tried:

"itemCount":{
      "type": "object"
    "additionalProperties": {"string", "integer"}

    }
+4
source share
1 answer

You can:

{
  "type": "object",
  "properties": {
    "itemType": {"$ref": "#/definitions/mapInt"},
    "itemCount": {"$ref": "#/definitions/mapInt"}
  },
  "definitions": {
    "mapInt": {
      "type": "object",
      "additionalProperties": {"type": "integer"}
    }
  }
}
+7
source

Source: https://habr.com/ru/post/1661631/


All Articles