如何为Map <string,integer =“”>定义JSON模式?

时间:2016-11-22 19:43:53

标签: json schema geojson jsonschema json-schema-validator

我有一个json:

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

这里的itemType和itemCount是常见的,但不是它们里面的值(食物,NA,电子),它们会不断改变,但格式如下:Map

如何为这种通用结构定义Json Schema?

我试过了:

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

    }

2 个答案:

答案 0 :(得分:14)

你可以:

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

答案 1 :(得分:0)

{
    "type": "array",
    "maxItems": 125,
    "items": {
        "type": "array",
        "items": [
            { // key schema goes here },
            { // value schema goes here }
        ],
        "additionalItems": false
    }
}