JSON文档在JSON架构上验证失败
下面的Json模式和Json文档都是有效的Json。 只是我无法获得与Json模式相关的有效Json文档 我在说:不应该有其他属性时出错 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
“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"
}]
}
]