A JSON toolkit for Python developers.

marksparkza marksparkza Last update: Mar 17, 2024

jschon

Supported Python versions PyPI package version Documentation status Test status Code coverage MIT license Total downloads

A JSON toolkit for Python developers.

Features

  • JSON Schema validator implementation (drafts 2019-09, 2020-12)
    • Schema compilation and indexing
    • $ref loading from local and remote sources
    • Support for custom keywords, vocabularies and meta-schemas
    • Support for format validation
  • JSON class implementing the JSON data model
  • JSON Pointer (RFC 6901)
  • JSON Patch (RFC 6902)
  • Relative JSON Pointer (draft)

Installation

pip install jschon

For remote $ref support, the requests library is required. It may be installed with:

pip install jschon[requests]

Example

Create a JSON schema:

Validate JSON data:

Generate JSON Schema-conformant output:

>>> result.output('basic') { "valid": True, "annotations": [ { "instanceLocation": "", "keywordLocation": "/items", "absoluteKeywordLocation": "https://example.com/demo#/items", "annotation": True }, { "instanceLocation": "/0", "keywordLocation": "/items/anyOf/1/description", "absoluteKeywordLocation": "https://example.com/demo#/items/anyOf/1/description", "annotation": "Hey! We got an integer here!" }, { "instanceLocation": "/1", "keywordLocation": "/items/anyOf/0/description", "absoluteKeywordLocation": "https://example.com/demo#/items/anyOf/0/description", "annotation": "Cool! We got a string here!" } ] }

Subscribe to our newsletter