JSON input validates against schema, error in validators.py

1,403 views
Skip to first unread message

martin....@gmail.com

unread,
Nov 23, 2014, 3:07:39 PM11/23/14
to jsons...@googlegroups.com
Hi,

I get the following error

File "/usr/local/lib/python2.7/dist-packages/jsonschema-2.4.0-py2.7.egg/jsonschema/validators.py", line 381, in validator_for
    return meta_schemas.get(schema.get(u"$schema", u""), default)
AttributeError: 'str' object has no attribute 'get'



if I try to validate


{
  "DB":22,
  "values":[
    [
      "INT",
      44
    ],
    [
      "REAL",
      33.33
    ],
    [
      "CHAR",
      "b"
    ]
  ]
}



against

input_schema={
        "type": "object",
        "properties": {
            "DB": {
                "type": "number"
            },
            "values": {
                "type": "array",
                "items": [
                    {
                        "type": "array",
                        "items": [
                            {
                                "type": "string"
                            },
                            {
                                "type": [
                                    "number",
                                    "string",
                                    "boolean",
                                    "null"
                                ]
                            }
                        ]
                    }
                ],
         "additionalItems": true
            }
        }
    }


Has anyone of you experienced this or something like that?
I don't know where to start resolving this problem.
Thanks in advance!

notifi...@marco.link

unread,
Dec 9, 2014, 10:52:07 AM12/9/14
to jsons...@googlegroups.com
I ran into this error when I forgot to deserialize my string into a Python object using json.loads('your schema in a string')

nick...@gmail.com

unread,
Dec 25, 2014, 6:38:19 AM12/25/14
to jsons...@googlegroups.com
I am not sure that I have understood this correctly, but isn't the thing that jsonschema *doesn't* take a string as a parameter, but rather a dict, which is the result of json.loads()?

However, I would agree that this could be mentioned in the function description, currently it says "instance: the instance to validate", which doesn't specify whether instance it is a string or a dict.
I guess some of the questions here could be answered having a little bit more helpful docstrings. Personally, i think more is more in that regard.

//Nicklas

Julian Berman

unread,
Dec 25, 2014, 1:16:55 PM12/25/14
to jsons...@googlegroups.com
On Thursday, December 25, 2014 6:38:19 AM UTC-5, nick...@gmail.com wrote:
I am not sure that I have understood this correctly, but isn't the thing that jsonschema *doesn't* take a string as a parameter, but rather a dict, which is the result of json.loads()?


jsonschema.validate and friends take deserialized JSON yeah.
 
However, I would agree that this could be mentioned in the function description, currently it says "instance: the instance to validate", which doesn't specify whether instance it is a string or a dict.

The instance is whatever instance you're validating, which is a string, a dict, an int, or some other kind of object.
 
I guess some of the questions here could be answered having a little bit more helpful docstrings. Personally, i think more is more in that regard.


Yup, better docs would always be nice -- patches welcome if you've got an idea on how to improve the wording.

Cheers,

-J
Reply all
Reply to author
Forward
0 new messages