Skip to main content

jsonschema_to_zon - Convert your JSON Schema documents into valid Zon validators

Coverage Status

A python utility that allows reading and JSON Schema documents and converting them into zon validators that respect the schema defined in those files.

Developed as a companion project to zon.

Installation

Pip

This package is available on PyPI, so you can install it with pip:

pip install jsonschema-to-zon

Source

Alternatively, you can clone this repository and install it from source. Please make sure that you have uv installed on your system.

git clone https://github.com/Naapperas/jsonschema_to_zon
cd zon
uv pip install .

Usage

In order to use the library, you first create a Schema object. This Schema object contains parsed information about your JSON Schema document. From this Schema object, you can invoke the generate command to generate the final Zon validator instance.

schema = ... # Create Schema. Described below
validator = schema.generate()

# Now you are ready to use the API provided by 'zon'

Generating Schema objects

Currently, there are 3 ways to generate Schema objects: passing in a file path, passing the contents of the JSON Schemas document as a string, or passing these same contents as a Python dictionary. The first 2 methods require the use of a SchemaReader.

Reading from a file

The most commonly expected method of using the library is from parsing a centrally served JSON Schema document:

reader = SchemaReader()
schema = reader.read_file('/path/to/your/file')

# Now you can do whatever you want with your schema object.

Reading from a string

If your JSON Schema definition is not present in a file, but is served in some other way (reading a DB record or served as part of an HTTP response, for example), you can also use the same SchemaReader class to generate a corresponding Schema object.

SCHEMA_STR = ...

reader = SchemaReader()

schema = reader.read_str(SCHEMA_STR)

# Now you can do whatever you want with your schema object.

Parsing a Python dict object

If you decide to construct your schema programatically using any of dict-like types supported in Python (including custom types supporting dict-like operations), you can invoke Schema.parse to generate the correct Schema object for you:

SCHEMA_DICT = {...}

schema = Schema.parse(SCHEMA_DICT)

# Now you can do whatever you want with your schema object.

Examples

Examples of using jsonschema-to-zon will be created soon.

Documentation

Documentation is still not available, but it will be soon.

Tests

Tests can be found in the tests folder. jsonschema-to-zon uses pytest for unit testing.

To run the tests, simply run:

pytest test

Coverage can be found on Coveralls.

Contributing

Contribution guidelines can be found in CONTRIBUTING

Past and current contributors can be found in CONTRIBUTORS

License

This project is licensed under the MIT License - see the LICENSE file for details.

Release files for jsonschema-to-zon 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for jsonschema-to-zon 1.0.0
File Size Uploaded
jsonschema_to_zon-1.0.0.tar.gz 10.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for jsonschema-to-zon 1.0.0
File Interpreter ABI Platform
jsonschema_to_zon-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 18.4 kB

Release files / jsonschema_to_zon-1.0.0.tar.gz

Download URL jsonschema_to_zon-1.0.0.tar.gz
Size 10.1 kB
Tags Source
SHA-256 checksum
How to use checksums
33c4ef26ba3ef894bfeaa6acfba2b040c78c327738162695523ee9cd94f9db3a
BLAKE2b-256 checksum
How to use checksums
925964eaddf27284f1482c6c1841f9a5ff06f545dc2f30c915fe1c753abebcd0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.10

Release files / jsonschema_to_zon-1.0.0-py3-none-any.whl

Download URL jsonschema_to_zon-1.0.0-py3-none-any.whl
Size 8.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1bdd4dded87c4738e8280d7b24dae6acbaff1bc919bef49c225986aa2c0b923e
BLAKE2b-256 checksum
How to use checksums
3dd81a3a129b9b5e09e516f956ef95b8f824e6c71ba6d29410b76478495e7d71
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.10

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page