2017-01-30 15 views
1

Ниже схемы Json и Json Document оба действительны json. Его просто, что я не могу получить действительный документ Json по отношению к json-схеме.Документ JSON не прошел проверку на схеме JSON

Я получаю сообщение об ошибке сказав: НЕ должны иметь дополнительные свойства

Json Схема

{ 
    "$schema": "http://json-schema.org/draft-04/schema#", 
    "title": "Movies Schema", 
    "description": "Movies schema containing ratings and genres", 
    "type": "array", 
    "items": { 
    "type": "object", 
    "additionalProperties": false, 
    "properties": { 
     "id": { 
     "type": "number" 
     }, 
     "title": { 
     "type": "string" 
     }, 
     "release_date": { 
     "type": "string" 
     }, 
     "video": { 
     "type": "string" 
     }, 
     "IMDBURL": { 
     "type": "string" 
     }, 
     "genres": { 
     "type": "array" 
     } 
    }, 
    "required": [ 
     "id", 
     "title", 
     "release_date", 
     "video", 
     "IMDBURL", 
     "genres" 
    ] 
    }, 
    "users": { 
    "type": "object", 
    "additionalProperties": false, 
    "properties": { 
     "user_id": { 
     "type": "number" 
     }, 
     "ratings": { 
     "type": "number" 
     }, 
     "timestamps": { 
     "type": "string" 
     } 
    }, 
    "required": [ 
     "user_id", 
     "ratings", 
     "timestamps" 
    ] 
    } 
} 

JSON Документ

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

ответ

1

Свойство "users" отсутствует в схеме, поэтому дополнительное свойство, поэтому оно нарушает настройку "additionalProperties": false.

Если вы определяете свойство "users" в схеме, то ваш документ будет действителен.

+0

Проверьте, что он существует, прокрутите страницу внизу. –

+0

в вашем объекте JSON, «пользователь» является частью «фильма», поэтому в вашей схеме вы должны добавить «пользователь» в качестве поля в вашей схеме видео –

0

Проблема была связана с расположением дополнительных объектов. , потому что пользователь имеет массив типов с большим количеством объектов. Свойства элемента предполагают, чтобы иметь additionalProperties не обертка "пользователи": {}, но "запись": {}

Решение

Json Schema

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

 Смежные вопросы

  • Нет связанных вопросов^_^