1.2 KiB
1.2 KiB
jsonschema
jsonschema
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):
...'Invalid' is not of type 'number' ValidationError:
You can find further information (installation instructions, mailing list) as well as the source code and issue tracker on our GitHub page.
Contents:
validate errors references creating faq
Indices and tables
genindex
search