Trying to understand why these JSON pass validation

96 views
Skip to first unread message

Tiago Ferraz

unread,
Jun 29, 2017, 4:14:05 AM6/29/17
to jsonschema - An implementation of JSON Schema for Python
Hi all,
I am trying to understand a few examples that for me should fail the validation but passes no matter I use validate() or Draft4Validator.validate()/is_valid().

the schema I am using is:

schema = {"type": "array",
"minItems": 1,
"properties": {
"id": {"type": "number"},
"name": {"type": "number"},
},
"required": ["id", "name"]
}

I found that the following JSON passes the validation
[{}] - it should fail because minItems and required properties are missing
[{"id": "test"}] - it should fails because required property "name" is missing and "id" is not a number. 

Is there something I am missing?

Best regards,
Tiago

knowingpark

unread,
Apr 10, 2019, 3:21:53 AM4/10/19
to jsonschema - An implementation of JSON Schema for Python
Yep sorry for being 1000 years late, but this problem helped me learn something so I am posting a reply.

The issue with your schema is that you are asserting that an array has keys (properties).
What you want to assert is that the array is composed of (has items of) dictionaries (objects)

 schema = {"type": "array",
         
"minItems": 1,

         
"items": {"type": "object",

                   
"properties": {
                       
"id": {"type": "number"},

                       
"name": {"type": "string"}
Reply all
Reply to author
Forward
0 new messages