ErrorTrees and AdditionalProperty Errors - Finding Unexpected Properties

36 views
Skip to first unread message

Kevin Engle

unread,
Dec 19, 2014, 7:13:51 PM12/19/14
to jsons...@googlegroups.com
I'm trying to validate some data against a jsonschema that has additionalProperties set to False.

What I want to do is find all the properties that fail the additionalProperties validation so I can handle them.

I first started with building a ErrorTree.

    validation = Draft4Validator(schema)
    tree = ErrorTree(validation.iter_errors(data))

I found that when I have a validation error though, I can't get the unexpected property despite it being mentioned in the message:

    print tree.message
Additional properties are not allowed ('test' was unexpected)

I went through the functions I could find in the documentation and source, but nothing I found seemed to deal with assembling the message. 

Is there a way to get the unexpected property without parsing the message?

nick...@gmail.com

unread,
Dec 25, 2014, 6:48:00 AM12/25/14
to jsons...@googlegroups.com

With parsing, do you mean json.parse? Because "getting" the property should be like instance["test"]. Or  what do you mean by not getting the property?
Or is "test" nested somewhere deep in the structure so that it simply isn't enough information?

//Nicklas

Julian Berman

unread,
Dec 25, 2014, 1:14:49 PM12/25/14
to jsons...@googlegroups.com
This is presumably another instance of https://github.com/Julian/jsonschema/issues/119 (which is waiting for a patch, would be awesome if you were interested).

-J
Reply all
Reply to author
Forward
0 new messages