我有一个json:
{
"itemType": {"food":22,"electrical":2},
"itemCount":{"NA":211}
}
这里的itemType和itemCount是常见的,但不是它们里面的值(食物,NA,电子),它们会不断改变,但格式如下:Map
如何为这种通用结构定义Json Schema?
我试过了:
"itemCount":{
"type": "object"
"additionalProperties": {"string", "integer"}
}
答案 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
}
}