Skip to main content

An implementation of JSON Schema validation for Python

Project description

jsonschema is an implementation of JSON Schema for Python (supporting 2.6+ 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'

Features

Release Notes

v1.3.0 adds better, more verbose tracebacks for validation errors that give some actual possibility of seeing what went wrong, particularly for the new anyOf, oneOf and allOf validators in draft 4.

The other notable change is that ErrorTrees now raise exceptions for keys that aren’t in the instance, to prevent typos.

__cause__ is also implemented on Py3 for format errors, if that floats your boat.

Running the Test Suite

jsonschema uses the wonderful Tox for its test suite. (It really is wonderful, if for some reason you haven’t heard of it, you really should use it for your projects).

Assuming you have tox installed (perhaps via pip install tox or your package manager), just run tox in the directory of your source checkout to 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.

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.

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 Distributions

jsonschema-1.3.0.zip (57.8 kB view details)

Uploaded Source

jsonschema-1.3.0.tar.gz (37.0 kB view details)

Uploaded Source

File details

Details for the file jsonschema-1.3.0.zip.

File metadata

  • Download URL: jsonschema-1.3.0.zip
  • Upload date:
  • Size: 57.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for jsonschema-1.3.0.zip
Algorithm Hash digest
SHA256 d1168efcc5c76f2bf31552e638d5c49f7bd474af3bc13a38396b0fbf646e10b8
MD5 02c0bacc8995926c6856b713adf4d2ce
BLAKE2b-256 0cb38c05965ff89f22416065bbd4f86530c87b209db47a23f9ff1b2609c01b87

See more details on using hashes here.

File details

Details for the file jsonschema-1.3.0.tar.gz.

File metadata

  • Download URL: jsonschema-1.3.0.tar.gz
  • Upload date:
  • Size: 37.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for jsonschema-1.3.0.tar.gz
Algorithm Hash digest
SHA256 c2a5b7bcf7f8e013e1ce2760c4c379a13719b2ce7006d295c50756f6ddd313e5
MD5 4fa8d609d997a2189fdcacd3ff2eaa3e
BLAKE2b-256 5b103eadf46b863dc47bf2ed54e41487ccd053c4c31587afadd3392fe9567871

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