JSON模式对象包含值
我想检查“obj”是否至少包含一个值“test”。但“obj”中的键是随机的 Json: 我的想法是使用其中一个,但它没有像我预期的那样工作: 模式Json:JSON模式对象包含值,json,jsonschema,json-schema-validator,Json,Jsonschema,Json Schema Validator,我想检查“obj”是否至少包含一个值“test”。但“obj”中的键是随机的 Json: 我的想法是使用其中一个,但它没有像我预期的那样工作: 模式Json: { "properties": { "title": { "type": "string" }, "obj": { "type": "object"
{
"properties": {
"title": {
"type": "string"
},
"obj": {
"type": "object",
"oneOf": [
{
"contains": {
"properties": {
"type": "string",
"desc":"test"
}
}
}
]
}
}
}
你可以使用“not”关键字来实现这一点。也就是说,我们可以构造一个断言:
- 属性“obj”必须存在
- “obj”的值是一个对象,必须至少有一个属性
- “obj”下的所有属性与“test”不匹配也不可能是真的
包含
仅适用于阵列。
{
"properties": {
"title": {
"type": "string"
},
"obj": {
"type": "object",
"oneOf": [
{
"contains": {
"properties": {
"type": "string",
"desc":"test"
}
}
}
]
}
}
}
{
"type": "object",
"required": ["obj"],
"properties": {
"obj": {
"type": "object",
"minProperties": 1,
"not": {
"additionalProperties": { "not": { "const": "test" } }
}
}
}
}