Re: JSON schema does not validate against valid data (validictory)

44 views
Skip to first unread message

Geraint

unread,
Apr 29, 2013, 12:08:25 PM4/29/13
to json-...@googlegroups.com
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 = {
    "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 objec

So is the schema for this data wrong?

Andreas

Geraint

unread,
Apr 29, 2013, 12:09:48 PM4/29/13
to json-...@googlegroups.com
I contacted the author of the jsonschema.net tool about this bug, actually, and they said it would be fixed, but that was a little while ago...
Reply all
Reply to author
Forward
0 new messages