为字典的动态数组定义JSON模式



我想为下面的JSON定义JSON模式。我的困惑在于如何定义乡村词典数组("country_details"(。国家名单(美国、印度(是动态的,事先不知道。

{
"map_id": 123456789,
"country_details": {"US": [1, 2, 3], "IN": [4, 5, 6]}
}

如果要将country_details设置为每个属性(国家/地区(都有一个数字数组作为其值的对象,additionalProperties/unevaluatedProperties可能会有所帮助。使用size可以防止出现空对象。

{
"$schema": "http://json-schema.org/draft-07/schema",
"type": "object",
"title": "The root schema",
"description": "The root schema comprises the entire JSON document.",
"default": {},
"examples": [
{
"map_id": 123456789,
"country_details": {
"US": [1, 2, 3],
"IN": [4, 5, 6]
}
}
],
"required": [
"map_id",
"country_details"
],
"properties": {
"map_id": {
"$id": "#/properties/map_id",
"type": "integer",
"title": "The map_id schema",
"description": "An explanation about the purpose of this instance.",
"default": 0,
"examples": [
123456789
]
},
"country_details": {
"$id": "#/properties/country_details",
"default": {},
"description": "An explanation about the purpose of this instance.",
"title": "The country_details schema",
"type": "object",
"examples": [
{
"US": [1, 2, 3]
}
],
"minProperties": 1,
"unevaluatedProperties": {
"type": "array",
"items": {
"type": "number",
"additionalItems": true
}
}
}
},
"additionalProperties": true
}

最新更新