Skip to content

How to get all errors of validate(instance, schema)? #1180

Closed Answered by Freed-Wu
Freed-Wu asked this question in Q&A
Discussion options

You must be logged in to vote

https://python-jsonschema.readthedocs.io/en/stable/errors/:

schema = {
    "items": {
        "anyOf": [
            {"type": "string", "maxLength": 2},
            {"type": "integer", "minimum": 5}
        ]
    }
}
instance = [{}, 3, "foo"]
v = Draft202012Validator(schema)
errors = sorted(v.iter_errors(instance), key=lambda e: e.path)

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Freed-Wu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant