动态数组的json模式 [英] json schema for dynamic array
本文介绍了动态数组的json模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下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模式文件,以验证请求.
For the above json i need to write a json schema file which will valdiates the request.
但是问题出在数组中,每个项目的键值都动态变化.如果它是一个恒定值,我可以写,但是不做动态模式
but the problem is in array the key value for each item changes dynamically. If it is some constant value i can write but don't how to do the dynamic pattern
我得到的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"
}
}
}
}
}
}
}
}
有人可以告诉您需要对架构进行哪些更改
Can some one tell what changes need to be done for schema
推荐答案
这是patternProperties
的用途.
在这里,看来您的对象成员键始终是数字;因此,您可以编写如下内容:
Here it seems your object member keys are always digits; therefore you can write things like this:
"type": "object",
"patternProperties": {
"^\\d+$": {
"type": "object",
"etc": "etc"
}
}
这篇关于动态数组的json模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文