[英]JSON schema does not validate against valid data (validictory)
以下數據+ JSON模式(使用具有相同數據的JSON模式生成器生成)應該正確驗證。 但是我在這里收到了一個valdation錯誤。
驗證基於驗證模塊。
import json
import validictory
import jsonschema
data = [{u'text':
u'<h1>The quick brown fox</h1>',
u'title': u'hello world',
u'location': u'Berlin',
u'created': u'2013-03-12T12:13:14'}]
schema = {
"$schema": "http://json-schema.org/draft-03/schema",
"id": "http://jsonschema.net",
"required": False,
"type": "object" ,
"properties": {
"0" : {
"id": "http://jsonschema.net/0",
"required": False,
"type": "object" ,
"properties": {
"created" : {
"id": "http://jsonschema.net/0/created",
"required": False,
"type": "string"
},
"location" : {
"id": "http://jsonschema.net/0/location",
"required": False,
"type": "string"
},
"text" : {
"id": "http://jsonschema.net/0/text",
"required": False,
"type": "string"
},
"title" : {
"id": "http://jsonschema.net/0/title",
"required": False,
"type": "string"
}
}
}
}
}
print validictory.validate(data,schema)
validictory.validator.FieldValidationError: Value [{u'text': u'<h1>The quick brown fox</h1>', u'created': u'2013-03-12T12:13:14', u'location': u'Berlin', u'title': u'hello world'}] for field '_data' is not of type object
您的驗證錯誤告訴您問題是什么......
它說Value [{u'text': u'<h1>The quick brown fox</h1>', u'created': u'2013-03-12T12:13:14', u'location': u'Berlin', u'title': u'hello world'}] for field '_data' is not of type object
,它不是,它是一個list
。 您需要驗證其內容, ie data[0]
,而不是整個列表。
此外,看起來你在jsonschema.net修改了它們如何使用id
之前生成了這個模式,這在規范下是不正確的,所以你可能想要刪除那些id
屬性。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.