如何为一般属性值设置 JSON 验证模式
How to set JSON validation schema for general properties values
我想使用架构验证 JSON(目前是草案 6,但如果需要我们可以升级)。我的情况是一个具有属性的对象,其值都具有相同的结构,例如:
{
"blueFoo": {
"bar1": "someValue",
"bar2": "differentValue"
},
"redFoo": {
"bar1": "someOtherValue",
"bar2": "LoremYpsum"
},
"purpleFoo": {
"bar1": "anotherString",
"bar2": "nextValue"
},
...
}
有没有办法为一般 属性 值设置验证架构?类似于:
{
"type": "object",
"propertyValue": {
"type": "object",
"required": ["bar1", "bar2"],
"additionalProperties": false,
"properties": {
"bar1": {"type": "string"},
"bar2": {"type": "string"}
}
}
}
谢谢。
additionalProperties
正是为了这个目的:
{
"type": "object",
"additionalProperties": {
"properties": {
"bar1": {"type": "string"},
"bar2": {"type": "string"}
},
"required": ["bar1", "bar2"],
"additionalProperties": false
}
}
我想使用架构验证 JSON(目前是草案 6,但如果需要我们可以升级)。我的情况是一个具有属性的对象,其值都具有相同的结构,例如:
{
"blueFoo": {
"bar1": "someValue",
"bar2": "differentValue"
},
"redFoo": {
"bar1": "someOtherValue",
"bar2": "LoremYpsum"
},
"purpleFoo": {
"bar1": "anotherString",
"bar2": "nextValue"
},
...
}
有没有办法为一般 属性 值设置验证架构?类似于:
{
"type": "object",
"propertyValue": {
"type": "object",
"required": ["bar1", "bar2"],
"additionalProperties": false,
"properties": {
"bar1": {"type": "string"},
"bar2": {"type": "string"}
}
}
}
谢谢。
additionalProperties
正是为了这个目的:
{
"type": "object",
"additionalProperties": {
"properties": {
"bar1": {"type": "string"},
"bar2": {"type": "string"}
},
"required": ["bar1", "bar2"],
"additionalProperties": false
}
}