Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用于验证数组中多个类似对象的JSON模式_Json_Jsonschema - Fatal编程技术网

用于验证数组中多个类似对象的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

如果我希望数组的元素(都是对象)都遵循相同的模式,那么在JSON模式中会使用什么关键字

例如:

"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"
  ]
}