Skip to main content

JSON Schema Utils

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

Status Python Version Badges License

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

A docker image is also available:

docker run --rm -v .:/app/workspace docker.io/zx80/jsu:latest --version

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 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 json-schema-utils 1.0.0
File Size Uploaded Provenance Actions
json_schema_utils-1.0.0.tar.gz 78.0 kB Without provenance Details for json_schema_utils-1.0.0.tar.gz

Built distribution (wheel)

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

Total release size: 157.2 kB

Release files / json_schema_utils-1.0.0.tar.gz

Download URL json_schema_utils-1.0.0.tar.gz
Size 78.0 kB
Tags Source
SHA-256 checksum
How to use checksums
82b1d5df9a898c9a5e3040efc9ecd756d242629bd59f276eaf086ba2686df207
BLAKE2b-256 checksum
How to use checksums
8a7aa13957bf80c7c5fc76dd05d8b029856b42456da37be4648e1706b14ca069
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.4

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

Download URL json_schema_utils-1.0.0-py3-none-any.whl
Size 79.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c4c8fd1b6792dea600ebcfdc1d615466ae231dbdff095ce917452be1c44e0445
BLAKE2b-256 checksum
How to use checksums
cd4bb8b88dd6493d830a768b8e77613df33bf3bd6a411275a500d0eeb9570d99
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.4

Security for json-schema-utils 1.0.0

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

1.0.0 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