Skip to main content

A library that allows converting from a JSON Schema document to a Zon-compatible validator.

Project description

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.

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

jsonschema_to_zon-1.0.0.tar.gz (10.1 kB view details)

Uploaded Source

Built Distribution

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

jsonschema_to_zon-1.0.0-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file jsonschema_to_zon-1.0.0.tar.gz.

File metadata

  • Download URL: jsonschema_to_zon-1.0.0.tar.gz
  • Upload date:
  • Size: 10.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.10

File hashes

Hashes for jsonschema_to_zon-1.0.0.tar.gz
Algorithm Hash digest
SHA256 33c4ef26ba3ef894bfeaa6acfba2b040c78c327738162695523ee9cd94f9db3a
MD5 431f0ced2672b3fbd54ec9cd6557cdfc
BLAKE2b-256 925964eaddf27284f1482c6c1841f9a5ff06f545dc2f30c915fe1c753abebcd0

See more details on using hashes here.

File details

Details for the file jsonschema_to_zon-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for jsonschema_to_zon-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1bdd4dded87c4738e8280d7b24dae6acbaff1bc919bef49c225986aa2c0b923e
MD5 687767a5c478b4c6d94e653869ba68b5
BLAKE2b-256 3dd81a3a129b9b5e09e516f956ef95b8f824e6c71ba6d29410b76478495e7d71

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