JSON Schema Utils
Project description
JSON Schema Utils
Random utilities to analyze and manipulate 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
enumtoconst. - 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 either jsonschema or jschon implementations.
jsu-check tests/foo.schema.json tests/foo.*.value.json
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 subset should comply with some restrictions described in Section 6 of An Analysis of Defects in Public JSON Schemas by Claire Yannou-Medrala and Fabien Coelho:
const,enum,$ref,type,allOf,anyOf,oneOfshould be exclusive.- some keywords are not supported:
multipleOf,contains - conditions
if then elseare translated to the logical equivalent:{if: C, then: T, else: E}is (C and T) or (not C and E)
jsu-model test/foo.schema.json
TODO
- Testing. CI.
- stats: warn instead of errors on unsure issues under
if/then/else/not. - propagate non type under containers (
*Of,if,then,else, reference?) to reduce false positive errors/warnings. - simplify: deduplicate constants in enum?
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file json_schema_utils-0.8.5.tar.gz.
File metadata
- Download URL: json_schema_utils-0.8.5.tar.gz
- Upload date:
- Size: 38.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
773d995afbad6b980a9fa8a66b41d6fe1fcde8091d7b54f03cf4b6830de34cf6
|
|
| MD5 |
204da73282bd3201ce739389788af44a
|
|
| BLAKE2b-256 |
0c9b1a74300f643bac8d5bcfa7316e42733df3b0c6e1bb9056b5b93086a0db8c
|
File details
Details for the file json_schema_utils-0.8.5-py3-none-any.whl.
File metadata
- Download URL: json_schema_utils-0.8.5-py3-none-any.whl
- Upload date:
- Size: 40.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6c958b6d5a1163149c95360d00ba0a5e10a3c07edf03077b38b8a00ace0a0f9e
|
|
| MD5 |
c3b2e028f7e91a9ebf5866578f52a634
|
|
| BLAKE2b-256 |
91a55b34d88c07f498487c65e0958ff304bf326007f96315268fcd22db590adb
|