Reputation: 51
The following data + JSON schema (generated from using JSON Schema Generator with the same data) is supposed to validate correctly. However instead I receive a valdation error here.
The validation is based on the validictory module.
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
Upvotes: 4
Views: 3255
Reputation: 3429
Your validation error tells you what the problem is...
It says 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
,
which it isn't, it's a list
. You need to validate its contents i.e. data[0]
, not the whole list.
Also, it looks like you generated this schema before jsonschema.net fixed how they use id
, which was incorrect under the spec, so you probably want to remove thoseid
properties.
Upvotes: 1