【发布时间】:2013-07-29 16:56:05
【问题描述】:
我想弄清楚如何在我的 json-schema 对象数组上设置 required。 required 属性适用于对象而不是数组。
这是我的 json 架构的项目部分:
"items": {
"type": "array",
"properties": {
"item_id": {"type" : "number"},
"quantity": {"type": "number"},
"price": {"type" : "decimal"},
"title": {"type": "string"},
"description": {"type": "string"}
},
"required": ["item_id","quantity","price","title","description"],
"additionalProperties" : false
}
这是我发送过来的 json 数组。 json 验证应该失败,因为我没有在这些项目中传递描述。
"items": [
{
"item_id": 1,
"quantity": 3,
"price": 30,
"title": "item1 new name"
},
{
"item_id": 1,
"quantity": 16,
"price": 30,
"title": "Test Two"
}
]
【问题讨论】:
标签: json jsonschema