A pythonic, extensible JSON Schema implementation.
Project description
Jschon
Welcome to Jschon, a JSON Schema implementation for Python!
Features
- Full support for drafts 2019-09 and 2020-12 of the JSON Schema specification.
- RFC 6901-conformant JSON Pointer implementation.
- JSON data model.
Installation
pip install jschon
Usage
For a demonstration, let's implement this example:
from jschon.catalogue import jsonschema_2020_12
from jschon.json import JSON
from jschon.jsonschema import JSONSchema
# initialize the JSON Schema 2020-12 metaschema and vocabularies
jsonschema_2020_12.initialize()
# define an extensible tree schema
tree_schema = JSONSchema({
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://example.com/tree",
"$dynamicAnchor": "node",
"type": "object",
"properties": {
"data": True,
"children": {
"type": "array",
"items": {
"$dynamicRef": "#node"
}
}
}
}).validate() # validate the schema against its metaschema
# define a strict-tree schema, which guards against misspelled properties
strict_tree_schema = JSONSchema({
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://example.com/strict-tree",
"$dynamicAnchor": "node",
"$ref": "tree",
"unevaluatedProperties": False
}).validate() # validate the schema against its metaschema
# declare a JSON instance with a misspelled field
tree_instance = JSON({
"children": [{"daat": 1}]
})
print(tree_schema.evaluate(tree_instance).valid) # True
print(strict_tree_schema.evaluate(tree_instance).valid) # False
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
jschon-0.1.1.tar.gz
(26.4 kB
view hashes)
Built Distribution
jschon-0.1.1-py3-none-any.whl
(41.8 kB
view hashes)