Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.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架构上验证失败_Json_Jsonschema_Json Schema Validator - Fatal编程技术网

JSON文档在JSON架构上验证失败

JSON文档在JSON架构上验证失败,json,jsonschema,json-schema-validator,Json,Jsonschema,Json Schema Validator,下面的Json模式和Json文档都是有效的Json。 只是我无法获得与Json模式相关的有效Json文档 我在说:不应该有其他属性时出错 Json模式 JSON文档 架构中缺少“users”属性,因此它是一个附加属性,因此它违反了“additionalProperties”:false设置 如果在架构中定义“users”属性,则文档将有效。问题在于附加属性的位置。 因为用户是数组类型,有很多对象。假定项的属性具有附加属性,而不是包装器“users”:{},而是“item”:{} 解决方案 Jso

下面的Json模式和Json文档都是有效的Json。 只是我无法获得与Json模式相关的有效Json文档

我在说:不应该有其他属性时出错

Json模式 JSON文档 架构中缺少
“users”
属性,因此它是一个附加属性,因此它违反了
“additionalProperties”:false
设置


如果在架构中定义
“users”
属性,则文档将有效。

问题在于附加属性的位置。 因为用户是数组类型,有很多对象。假定项的属性具有附加属性,而不是包装器“users”:{},而是“item”:{}

解决方案 Json模式

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "array",
  "items": {
    "type": "object",
    "additionalProperties": false,
    "properties": {
      "id": {
        "type": "integer"
      },
      "title": {
        "type": "string"
      },
      "release_date": {
        "type": "string"
      },
      "video": {
        "type": "string"
      },
      "IMDBURL": {
        "type": "string"
      },
      "genres": {
        "type": "array",
        "items": {
          "type": "string"
        }
      },
      "users": {
        "type": "array",
        "items": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "user_id": {
              "type": "integer"
            },
            "ratings": {
              "type": "integer"
            },
            "timestamps": {
              "type": "string"
            }
          },
          "required": [
            "user_id",
            "ratings",
            "timestamps"
          ]
        }
      }
    },
    "required": [
      "id",
      "title",
      "release_date",
      "video",
      "IMDBURL",
      "genres",
      "users"
    ]
  }
}
Json文档

[
  {
    "id": 1,
    "title": "Kung Fu Panda",
    "release_date": "01-01-2000",
    "video": "",
    "IMDBURL": "link.com",
    "genres": [
      "abc",
      "def"
    ],
    "users": [{
      "user_id": 2,
      "ratings": 3,
      "timestamps": "2342478"
    },
{
      "user_id": 2,
      "ratings": 3,
      "timestamps": "2342478"
    },
{
      "user_id": 2,
      "ratings": 3,
      "timestamps": "2342478"
    },
{
      "user_id": 2,
      "ratings": 3,
      "timestamps": "2342478"
    }]
  },
{
    "id": 1,
    "title": "Kung Fu Panda",
    "release_date": "01-01-2000",
    "video": "",
    "IMDBURL": "link.com",
    "genres": [
      "abc",
      "def"
    ],
    "users": [{
      "user_id": 2,
      "ratings": 3,
      "timestamps": "2342478"
    },
{
      "user_id": 2,
      "ratings": 3,
      "timestamps": "2342478"
    },
{
      "user_id": 2,
      "ratings": 3,
      "timestamps": "2342478"
    },
{
      "user_id": 2,
      "ratings": 3,
      "timestamps": "2342478"
    }]
  },
{
    "id": 1,
    "title": "Kung Fu Panda",
    "release_date": "01-01-2000",
    "video": "",
    "IMDBURL": "link.com",
    "genres": [
      "abc",
      "def"
    ],
    "users": [{
      "user_id": 2,
      "ratings": 3,
      "timestamps": "2342478"
    },
{
      "user_id": 2,
      "ratings": 3,
      "timestamps": "2342478"
    },
{
      "user_id": 2,
      "ratings": 3,
      "timestamps": "2342478"
    },
{
      "user_id": 2,
      "ratings": 3,
      "timestamps": "2342478"
    }]
  }
]

请检查它是否存在,在底部滚动。在JSON对象中,“user”是“movie”的一部分,因此在您的模式中,您必须将“user”作为字段添加到您的movie模式中
{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "array",
  "items": {
    "type": "object",
    "additionalProperties": false,
    "properties": {
      "id": {
        "type": "integer"
      },
      "title": {
        "type": "string"
      },
      "release_date": {
        "type": "string"
      },
      "video": {
        "type": "string"
      },
      "IMDBURL": {
        "type": "string"
      },
      "genres": {
        "type": "array",
        "items": {
          "type": "string"
        }
      },
      "users": {
        "type": "array",
        "items": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "user_id": {
              "type": "integer"
            },
            "ratings": {
              "type": "integer"
            },
            "timestamps": {
              "type": "string"
            }
          },
          "required": [
            "user_id",
            "ratings",
            "timestamps"
          ]
        }
      }
    },
    "required": [
      "id",
      "title",
      "release_date",
      "video",
      "IMDBURL",
      "genres",
      "users"
    ]
  }
}
[
  {
    "id": 1,
    "title": "Kung Fu Panda",
    "release_date": "01-01-2000",
    "video": "",
    "IMDBURL": "link.com",
    "genres": [
      "abc",
      "def"
    ],
    "users": [{
      "user_id": 2,
      "ratings": 3,
      "timestamps": "2342478"
    },
{
      "user_id": 2,
      "ratings": 3,
      "timestamps": "2342478"
    },
{
      "user_id": 2,
      "ratings": 3,
      "timestamps": "2342478"
    },
{
      "user_id": 2,
      "ratings": 3,
      "timestamps": "2342478"
    }]
  },
{
    "id": 1,
    "title": "Kung Fu Panda",
    "release_date": "01-01-2000",
    "video": "",
    "IMDBURL": "link.com",
    "genres": [
      "abc",
      "def"
    ],
    "users": [{
      "user_id": 2,
      "ratings": 3,
      "timestamps": "2342478"
    },
{
      "user_id": 2,
      "ratings": 3,
      "timestamps": "2342478"
    },
{
      "user_id": 2,
      "ratings": 3,
      "timestamps": "2342478"
    },
{
      "user_id": 2,
      "ratings": 3,
      "timestamps": "2342478"
    }]
  },
{
    "id": 1,
    "title": "Kung Fu Panda",
    "release_date": "01-01-2000",
    "video": "",
    "IMDBURL": "link.com",
    "genres": [
      "abc",
      "def"
    ],
    "users": [{
      "user_id": 2,
      "ratings": 3,
      "timestamps": "2342478"
    },
{
      "user_id": 2,
      "ratings": 3,
      "timestamps": "2342478"
    },
{
      "user_id": 2,
      "ratings": 3,
      "timestamps": "2342478"
    },
{
      "user_id": 2,
      "ratings": 3,
      "timestamps": "2342478"
    }]
  }
]