I'm afraid yes - that schema is wrong.
The JSON Schema Generator is slightly buggy - it only accepts "object"s as top-level data. You, however, want the top-level type to be "array":
schema = {
"type": "
array" ,
"items": {
"type": "object" ,
"properties": {
...
}
}
}
On Monday, April 29, 2013 5:00:19 PM UTC+1, Andreas Jung wrote:
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 = {
"required": False,
"type": "object" ,
"properties": {
"0" : {
"required": False,
"type": "object" ,
"properties": {
"created" : {
"required": False,
"type": "string"
},
"location" : {
"required": False,
"type": "string"
},
"text" : {
"required": False,
"type": "string"
},
"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 objec
So is the schema for this data wrong?
Andreas