Newbie Newbie - 17 days ago 4
JSON Question

How to define JSON Schema for Map<String, Integer>?

I have a json :

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


Here the itemType and itemCount will be common but not the values inside them (food, NA, electrical) which will be keep changing but the will be in the format : Map

How do I define Json Schema for such generic structure ?

I tried :

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

}

esp esp
Answer

You can:

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