Skip to main content

JSON Schema Utils

Random utilities to analyze, manipulate, simplify, convert or compile JSON Schema.

Installation

Install latest version with pip from PyPI or directly from GitHub:

python -m venv venv
source venv/bin/activate
# from PyPI:
pip install json_schema_utils
# OR from latest sources:
pip install git+https://github.com/zx80/json-schema-utils.git

Inline Schema References

Replace references $ref by their definitions.

# no $id
jsu inline -m "file:// ./tests" tests/*.schema.json
# with $id
jsu inline -a tests/foo.schema.json

Simplify Schema

Apply various schema simplifications:

  • remove type-incompatible keywords and formats, with warnings.
  • try to move up list-of-one-schema *Of.
  • simplify type lists.
  • change list-of-one enum to const.
  • detect some cases of infeasible schemas.
  • remove uneffective keywords in corner cases.
jsu simpler tests/*.schema.json

Check JSON Values against a Schema

Check a JSON values match a given schema using jmc (jsu compile with jmc dynamic Python backend), jsonschema or jschon implementations.

jsu check tests/foo.schema.json tests/foo.*.value.json

Note: the corresponding external dependencies must be installed.

JSON Schema Stats and Issues

Generate a report about JSON schemas, including possible bugs.

jsu stats tests/*.schema.json

This script is extracted from JSON Schema Stats which has been updated to depend on this module.

JSON Prettyprinter

jsu pretty --indent 2 --sort-keys tests/*.schema.json

You could also use jq . for this purpose.

JSON Schema to JSON Model Conversion

Convert a subset of JSON Schema to JSON Model.

The converter is expected to fully supports JSON Schema draft3 to draft7. Note that our tools include a significant support for format assertions, with 80-95% of optional format tests being validated, usually in a safe way (i.e. false positives may occur, false negatives are avoided).

It partially supports draft 2019-09 and 2020-12. In particular, vocabularies are fully supported. However, there is a limited support for some features:

  • dynamic anchors and references
  • unevaluated items and properties

Moreover, this is a software, hence there may be bugs.

jsu model --format -o foo.model.json foo.schema.json

JSON Schema Compiler

Convert the input schema and generate C, JS, Python, Java, Perl or even PL/pgSQL code.

The compiler first converts the schema to a model (see previous command), then proceeds to compile the generated model to actual code using the JSON Model Compiler as a backend.

# generate a python script
jsu compile -o some.py some.schema.json
# run the script to validate values
./some.py val1.json val2.json

The generated code (here the some.py Python script) needs some runtime which is installed with the compiler python module. Other languages require specific runtimes, which are available in the docker.io/zx80/jmc container image, or can be installed independently, see JSON Model HOWTO.

JSON Schema compliance Bowtie badges:

  • C Supported Dialects,
  • Python Supported Dialects,
  • JavaScript Supported Dialects,
  • Java Supported Dialects,
  • Perl Supported Dialects.

JSON Type Definition Converter

Command jsu jtd converts a JTD type declaration to JSON Schema or JSON Model:

jsu jtd -o foo.schema.json foo.jtd.json
jsu jtd -o foo.model.json foo.jtd.json

JSU Test Runner

Run a JSON Schema Test Suite case.

jsu runner --debug --resilient --map http://localhost:1234/=file://$JSTS_HOME/remotes/ -V 7 $JSTS_HOME/tests/draft7/ref.json

TODO

  • propagate non type under containers (*Of, if, then, else, reference?) to reduce false positive errors/warnings.
  • simplify: deduplicate constants in enum?

Metadata

Release files for json-schema-utils 0.9.24

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

Source distribution (sdist)

Source distribution for json-schema-utils 0.9.24
File Size Uploaded Provenance Actions
json_schema_utils-0.9.24.tar.gz 77.0 kB Without provenance Details for json_schema_utils-0.9.24.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for json-schema-utils 0.9.24
File Interpreter ABI Platform Actions
json_schema_utils-0.9.24-py3-none-any.whl Python 3 none any Details for json_schema_utils-0.9.24-py3-none-any.whl

Total release size: 155.9 kB

Release files / json_schema_utils-0.9.24.tar.gz

Download URL json_schema_utils-0.9.24.tar.gz
Size 77.0 kB
Tags Source
SHA-256 checksum
How to use checksums
f9562f2d38417ade8f02f4e1a4a3a32a4cc9e9a065d72d178c4b4f738f8335a2
BLAKE2b-256 checksum
How to use checksums
c4892a7b34d836fb1a0636e27c3187afdd3a33921dd5ceb7e1207b35792aa9e6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / json_schema_utils-0.9.24-py3-none-any.whl

Download URL json_schema_utils-0.9.24-py3-none-any.whl
Size 78.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
aa92c224f3ec8d8e32fa1bb6c1603b4bf51eed9ae78ebd68abfdc2476be0f2a1
BLAKE2b-256 checksum
How to use checksums
dc7b3665fd921459e92c0da9f8f485809fb1ca7a8fa9dc91b29c5af1c03c1b85
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Security for json-schema-utils 0.9.24

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.9.24 This release

2 release files No provenance

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