Skip to main content

An implementation of JSON Schema validation for Python

Project description

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

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

>>> from jsonschema import validate

>>> # A sample schema, like what we'd get from json.load()
>>> schema = {
...     "type" : "object",
...     "properties" : {
...         "price" : {"type" : "number"},
...         "name" : {"type" : "string"},
...     },
... }

>>> # If no exception is raised by validate(), the instance is valid.
>>> validate(instance={"name" : "Eggs", "price" : 34.99}, schema=schema)

>>> validate(
...     instance={"name" : "Eggs", "price" : "Invalid"}, schema=schema,
... )                                   # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
    ...
ValidationError: 'Invalid' is not of type 'number'

It can also be used from the command line by installing check-jsonschema.

Features

Installation

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

$ pip install jsonschema

Extras

Two extras are available when installing the package, both currently related to format validation:

  • format

  • format-nongpl

They can be used when installing in order to include additional dependencies, e.g.:

$ pip install jsonschema'[format]'

Be aware that the mere presence of these dependencies – or even the specification of format checks in a schema – do not activate format checks (as per the specification). Please read the format validation documentation for further details.

About

I’m Julian Berman.

jsonschema is on GitHub.

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

You can also generally find me on Libera (nick: Julian) in various channels, including #python.

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

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

Release Information

v4.18.0

This release majorly rehaul’s the way in which JSON Schema reference resolution is configured. It does so in a way that should be backwards compatible, preserving old behavior whilst emitting deprecation warnings.

  • jsonschema.RefResolver is now deprecated in favor of the new referencing library. referencing will begin in beta, but already is more compliant than the existing $ref support. This change is a culmination of a meaningful chunk of work to make $ref resolution more flexible and more correct. Backwards compatibility should be preserved for existing code which uses RefResolver, though doing so is again now deprecated, and all such use cases should be doable using the new APIs. Please file issues on the referencing tracker if there is functionality missing from it, or here on the jsonschema issue tracker if you have issues with existing code not functioning the same, or with figuring out how to change it to use referencing.

  • Support for Python 3.7 has been dropped, as it is nearing end-of-life. This should not be a “visible” change in the sense that requires-python has been updated, so users using 3.7 should still receive v4.17.3 when installing the library.

  • On draft 2019-09, unevaluatedItems now properly does not consider items to be evaluated by an additionalItems schema if items is missing from the schema, as the specification says in this case that additionalItems must be completely ignored.

  • Fix the date format checker on Python 3.11 (when format assertion behavior is enabled), where it was too liberal (#1076).

  • Speed up validation of unevaluatedProperties (#1075).

Deprecations

  • jsonschema.RefResolver – see above for details on the replacement

  • jsonschema.RefResolutionError – see above for details on the replacement

  • importing jsonschema.ErrorTree – instead import it via jsonschema.exceptions.ErrorTree

  • importing jsonschema.FormatError – instead import it via jsonschema.exceptions.FormatError

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jsonschema-4.18.0a5.tar.gz (310.5 kB view hashes)

Uploaded Source

Built Distribution

jsonschema-4.18.0a5-py3-none-any.whl (80.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page