Skip to main content

A pythonic, extensible JSON Schema implementation.

Project description

Test Status Code Coverage PyPI Package Version Python Versions Documentation Status License

jschon is a pythonic and extensible implementation of the JSON Schema specification.

Features

  • JSON Schema validator implementation (2019-09, 2020-12)
    • Format assertion supported via plug-in callables
    • Schema compilation and indexing
    • $ref loading from local and (coming soon!) remote sources
    • Support for custom keywords, vocabularies and meta-schemas
  • JSON class implementing the JSON data model
  • JSON pointer implementation (RFC 6901)

Installation

pip install jschon

Usage

Create a JSON schema:

from jschon import create_catalog, JSON, JSONSchema

create_catalog('2020-12')

demo_schema = JSONSchema({
    "$id": "https://example.com/demo",
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "array",
    "items": {
        "anyOf": [
            {
                "type": "string",
                "description": "Cool! We got a string here!"
            },
            {
                "type": "integer",
                "description": "Hey! We got an integer here!"
            }
        ]
    }
})

Validate JSON data:

result = demo_schema.evaluate(
    JSON([12, "Monkeys"])
)

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!"
        }
    ]
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for jschon, version 0.7.3
Filename, size File type Python version Upload date Hashes
Filename, size jschon-0.7.3-py3-none-any.whl (49.3 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size jschon-0.7.3.tar.gz (35.8 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page