Skip to content

"required" field in nested dict #331

Closed
@phiweger

Description

@phiweger

I have a JSON schema like so:

{
    "properties": {
        "_id": {
            "type": "string"
        },
        "animal": {
            "type": "string"
        },
        "c": {
            "properties": {
                "danger": {
                    "type": "boolean"
                },
                "very": {
                    "type": "boolean"
                }
            },
            "required": [
                "danger"
            ],
            "type": "object"
        },
        "zoo": {
            "type": "string"
        }
    },
    "required": [
        "_id",
        "animal"
    ],
    "type": "object"
}

Validation only works at the top level:

from jsonschema import validate
rec = {'_id': '1', 'zoo': 'le', 'animal': 'lion'}
validate(rec, schema)  # success

However, I would expect the validation to fail, because I have no field ['c']['danger']. Am I doing something wrong or does jsonschema not validate nested "required" fields?

Thx a lot!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions