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 (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)

  • JSON document translation (experimental)

Installation

pip install jschon

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

pip install jschon[requests]

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.

Source Distribution

jschon-0.8.1.tar.gz (42.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jschon-0.8.1-py3-none-any.whl (58.4 kB view details)

Uploaded Python 3

File details

Details for the file jschon-0.8.1.tar.gz.

File metadata

  • Download URL: jschon-0.8.1.tar.gz
  • Upload date:
  • Size: 42.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.10

File hashes

Hashes for jschon-0.8.1.tar.gz
Algorithm Hash digest
SHA256 26962ea913d5f3f82ca69e660f30c801d9328c54e397cd38a3c3849c23ec36fd
MD5 93a06f528d923e222ee18832407b8d38
BLAKE2b-256 d09b5e5a33e03df4fb74db25ffc1a0d2639453692781366017ca3604ee078f94

See more details on using hashes here.

File details

Details for the file jschon-0.8.1-py3-none-any.whl.

File metadata

  • Download URL: jschon-0.8.1-py3-none-any.whl
  • Upload date:
  • Size: 58.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.10

File hashes

Hashes for jschon-0.8.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ba7d1972b25dda390b837c3bd0a4330ba57852c89c5904f8fe93760a66d7ed07
MD5 ba8d46ef267fc007287dcf58a94c59a2
BLAKE2b-256 b95799624507513982997251147064b1db49f5c600755f59f0e82e9290da20d9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page