Skip to main content

An implementation of JSON Schema validation for Python

Project description

PyPI version Supported Python versions Travis build status AppVeyor build status

jsonschema is an implementation of JSON Schema for Python (supporting 2.7+ including Python 3).

>>> 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({"name" : "Eggs", "price" : 34.99}, schema)

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

It can also be used from console:

$ jsonschema -i sample.json sample.schema

Features

Release Notes

Version 2.6.0 drops support for Python 2.6.X (ha ha) and contains a number of small improvements in error messages, as well as a bug fix for ErrorTree.

Running the Test Suite

If you have tox installed (perhaps via pip install tox or your package manager), running tox in the directory of your source checkout will run jsonschema’s test suite on all of the versions of Python jsonschema supports. Note that you’ll need to have all of those versions installed in order to run the tests on each of them, otherwise tox will skip (and fail) the tests on that version.

Of course you’re also free to just run the tests on a single version with your favorite test runner. The tests live in the jsonschema.tests package.

Benchmarks

jsonschema’s benchmarks make use of perf.

Running them can be done via tox -e perf, or by invoking the perf commands externally (after ensuring that both it and jsonschema itself are installed):

$ python -m perf jsonschema/benchmarks/test_suite.py --hist --output results.json

To compare to a previous run, use:

$ python -m perf compare_to --table reference.json results.json

See the perf documentation for more details.

Community

There’s a mailing list for this implementation on Google Groups.

Please join, and feel free to send questions there.

Contributing

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 Freenode (nick: tos9) in various channels, including #python.

If you feel overwhelmingly grateful, you can woo me with beer money via Google Pay with the email in my GitHub profile.

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-3.0.0a2.tar.gz (115.4 kB view details)

Uploaded Source

Built Distribution

jsonschema-3.0.0a2-py2.py3-none-any.whl (50.3 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file jsonschema-3.0.0a2.tar.gz.

File metadata

  • Download URL: jsonschema-3.0.0a2.tar.gz
  • Upload date:
  • Size: 115.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Python-urllib/2.7

File hashes

Hashes for jsonschema-3.0.0a2.tar.gz
Algorithm Hash digest
SHA256 aef58a18d83e4c5ea117d7ae1ba4238a6a84654fee6d0f32fd335ded63a1626e
MD5 40e6bc29789ef999471ac1aaf9ad846e
BLAKE2b-256 995fbfa0e2647efff46bc8b5def9dceacc810b31056eaf011feca3053ae85159

See more details on using hashes here.

File details

Details for the file jsonschema-3.0.0a2-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for jsonschema-3.0.0a2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 1ae9fe07aec50f07fc546a4432c93e2f23deeaa23bb67aef42d75d8aa496849b
MD5 98b7aba3aa4199867a2f92e6d5e4b34a
BLAKE2b-256 d2dd223df24ed72a113448cfae5a58ba122826d59280c836e5efb1c6ee5101ef

See more details on using hashes here.

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