Arrays 需要JSON模式数组
我试图弄清楚如何设置模式中所需的全局级别数组。我的示例JSON文件是:Arrays 需要JSON模式数组,arrays,json,jsonschema,Arrays,Json,Jsonschema,我试图弄清楚如何设置模式中所需的全局级别数组。我的示例JSON文件是: [ { "firstname": "Paul", "lastname": "McCartney" }, { "firstname": "John", "lastname": "Lennon" }, { "firstname": "George", "lastname": "Harrison"
[
{
"firstname": "Paul",
"lastname": "McCartney"
},
{
"firstname": "John",
"lastname": "Lennon"
},
{
"firstname": "George",
"lastname": "Harrison"
},
{
"firstname": "Ringo",
"lastname": "Starr"
}
]
如上所述,我希望顶层结构是一个数组,而不是一个对象。我从jsonschema.net获得的模式是(稍作修改):
但它失败了。您能帮我为顶级数组提供正确的JSON模式吗?要对输入数据有效,您只需要以下模式:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "array",
"id": "http://jsonschema.net",
"items": {
"type": "object",
"properties": {
"firstname": {
"type": "string"
},
"lastname": {
"type": "string"
}
},
"required": [
"firstname",
"lastname"
]}
}
你不需要做最高级的事情。如果文档是数组,那么文档不是可选的!如果您试图指定最小项目数,请尝试
minItems
。@cloudfeet不知道,谢谢!嗯,我明白了-我定义了无用的顶级required
字段。所需的数组元素级别就足够了。太好了,谢谢!
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "array",
"id": "http://jsonschema.net",
"items": {
"type": "object",
"properties": {
"firstname": {
"type": "string"
},
"lastname": {
"type": "string"
}
},
"required": [
"firstname",
"lastname"
]}
}