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 allows to convert 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

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.19

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.19
File Size Uploaded
json_schema_utils-0.9.19.tar.gz 74.1 kB Details

Built distribution (wheel)

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

Total release size: 152.5 kB

Release files / json_schema_utils-0.9.19.tar.gz

Download URL json_schema_utils-0.9.19.tar.gz
Size 74.1 kB
Tags Source
SHA-256 checksum
How to use checksums
cd7bad124e4dbae59c78a637fcc7a1187db25a1143e861d8e515805a105c661d
BLAKE2b-256 checksum
How to use checksums
1e7ec779d59e999bf2460f071d21d4ef2089635bc2bd19dcd4281b4c613e0f00
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.19-py3-none-any.whl

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

Release history Release notifications | RSS feed

0.9.20

2 release files

This release

0.9.19 This release

2 release files

0.9.18

2 release files

0.9.16

2 release files

0.9.15

2 release files

0.9.14

2 release files

0.9.13

2 release files

0.9.12

2 release files

0.9.11

2 release files

0.9.10

2 release files

0.9.9

2 release files

0.9.8

2 release files

0.9.6

2 release files

0.9.5

2 release files

0.9.4

2 release files

0.9.3

2 release files

0.9.2

2 release files

0.9.1

2 release files

0.9.0

2 release files

0.8.6

2 release files

0.8.5

2 release files

0.8.4

2 release files

0.8.3

2 release files

0.8.2

2 release files

0.8.1

2 release files

0.8

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