用于验证数组中多个类似对象的JSON模式
如果我希望数组的元素(都是对象)都遵循相同的模式,那么在JSON模式中会使用什么关键字 例如:用于验证数组中多个类似对象的JSON模式,json,jsonschema,Json,Jsonschema,如果我希望数组的元素(都是对象)都遵循相同的模式,那么在JSON模式中会使用什么关键字 例如: "data": [ { //validated "id": 1, "name": "Bob", "ready": "Not Ready" }, { //validated "id": 2, "name": "Steve", "ready": "Ready" }, { //not valid
"data":
[
{ //validated
"id": 1,
"name": "Bob",
"ready": "Not Ready"
},
{ //validated
"id": 2,
"name": "Steve",
"ready": "Ready"
},
{ //not validated, missing "ready"
"id": 3,
"name": "Ted"
}
]
将“数据”对象指定为类型数组,并指明每个项中所需的元素
{
"type": "object",
"properties": {
"data": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "integer"
},
"name": {
"type": "string"
},
"ready": {
"type": "string"
}
},
"required": [
"id",
"name",
"ready"
]
}
}
},
"required": [
"data"
]
}
将“数据”对象指定为类型数组,并指明每个项中所需的元素
{
"type": "object",
"properties": {
"data": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "integer"
},
"name": {
"type": "string"
},
"ready": {
"type": "string"
}
},
"required": [
"id",
"name",
"ready"
]
}
}
},
"required": [
"data"
]
}