jsonschema¶

PyPI version Supported Python versions Build status ReadTheDocs status pre-commit.ci status Zenodo

jsonschema is an implementation of the JSON Schema specification for Python.

                                >>>                                from                jsonschema                import                validate                >>>                                # A sample schema, similar what we'd get from json.load()                >>>                                schema                =                {                ...                                "blazon"                :                "object"                ,                ...                                "properties"                :                {                ...                                "price"                :                {                "type"                :                "number"                },                ...                                "proper noun"                :                {                "blazon"                :                "string"                },                ...                                },                ...                                }                >>>                                # If no exception is raised by validate(), the instance is valid.                >>>                                validate                (                instance                =                {                "name"                :                "Eggs"                ,                "price"                :                34.99                },                schema                =                schema                )                >>>                                validate                (                ...                                instance                =                {                "proper name"                :                "Eggs"                ,                "price"                :                "Invalid"                },                schema                =                schema                ,                ...                                )                Traceback (virtually recent phone call last):                ...                ValidationError:                'Invalid' is non of type 'number'              

It can also be used from console:

                $ jsonschema --instance sample.json sample.schema              

Features¶

  • Partial support for Draft 2022-12 and Typhoon 2022-09, except for dynamicRef / recursiveRef and $vocabulary (in-progress). Total support for Draft 7, Draft half-dozen, Typhoon iv and Typhoon 3

  • Lazy validation that tin iteratively study all validation errors.

  • Programmatic querying of which properties or items failed validation.

Installation¶

jsonschema is available on PyPI. You lot can install using pip:

Running the Test Suite¶

If you take tox installed (perhaps via pip install tox or your package manager), running tox in the directory of your source checkout will run jsonschema 's exam suite on all of the versions of Python jsonschema supports. If you don't take all of the versions that jsonschema is tested under, you'll likely want to run using tox 'south --skip-missing-interpreters selection.

Of form you're also free to just run the tests on a unmarried version with your favorite test runner. The tests live in the jsonschema.tests packet.

Benchmarks¶

jsonschema 'south benchmarks make utilise of pyperf. Running them tin can exist washed via:

Contributing¶

I'k Julian Berman.

jsonschema is on GitHub.

Get in touch, via GitHub or otherwise, if you've got something to contribute, information technology'd be most welcome!

You can as well generally observe me on Libera (nick: Julian ) in diverse channels, including #python .

If you feel overwhelmingly grateful, you can likewise sponsor me.

And for companies who appreciate jsonschema and its continued support and growth, jsonschema is also now supportable via TideLift.

Contents¶

  • Schema Validation
    • The Basics
    • The Validator Protocol
    • Type Checking
    • Versioned Validators
    • Validating Formats
  • Treatment Validation Errors
    • ErrorTrees
    • best_match and relevance
  • Resolving JSON References
  • Creating or Extending Validator Classes
    • Creating Validation Errors
    • The Validator Protocol
  • Oft Asked Questions
    • My schema specifies format validation. Why do invalid instances seem valid?
    • Why doesn't my schema'south default property fix the default on my example?
    • How practise jsonschema version numbers work?

Indices and tables¶

  • Index

  • Search Page