【发布时间】:2015-05-27 18:44:56
【问题描述】:
我有以下 json
{
"Dettype": "QTY",
"Details": [
{
"12568": {
"Id": 12568,
"qty":1,
"Freq":"2",
"Option": 0,
"promote":"yes"
},
"22456": {
"Id": 22456,
"qty":2,
"Freq":"3",
"Option": 1,
"promote":"no"
}
}
]
}
对于上面的 json,我需要编写一个 json 模式文件来验证请求。
但问题在于数组中每个项目的键值会动态变化。如果它是一些常数值,我可以写但不知道如何做动态模式
我得到的 JSON 模式
{
"type": "object",
"additionalProperties": true,
"properties": {
"Dettype": {
"type": "string"
},
"Details": {
"type": "array",
"items": {
"type": "object",
"additionalProperties": true,
"properties": {
"**DYNAMIC VALUE**": {
"type": "object",
"additionalProperties": true,
"properties": {
"Id": {
"type": "integer"
},
"qty": {
"type": "integer"
},
"Freq": {
"type": "string"
},
"Option": {
"type": "integer"
},
"promote": {
"type": "string"
}
}
}
}
}
}
}
}
有人能说出需要对架构进行哪些更改
【问题讨论】:
-
为什么数组中嵌入了一个对象?为什么它本身不是一个对象?
标签: json jsonschema json-schema-validator