Provides JSON tools:
-
jschon-sortsorts a JSON or YAML document according to its JSON Schema: object properties are ordered to match the order in which JSON Schema properties (that match them) are declared. -
jschon-remove-additional-propsremoves properties not defined in the JSON Schema.
The "jschon" name relates to it being based on the jschon library for JSON Schema handling.
Motivation
Per the JSON RFC, an object is an unordered collection. In practice, within serialized JSON or YAML files,
a particular order of properties can benefit readability: for example,
{"start": 10, "end": 20} read more naturally than naive lexicographic order of {"end": 20, "start": 10}
(that would result from json.dumps(..., sort_keys=True)).
While there are several
attempts
to introduce property ordering into JSON Schema, here we're taking a different approach.
By leveraging the fact that the JSON Schema itself is written with human maintainers in mind,
we can extrapolate the intuitive order from the JSON Schema definitions' ordering and apply it on the document itself.
Usage
Shell:
jschon-sort --schema ../schema.json file.yaml
API:
import jschon
import jschon_tools
jschon.create_catalog('2020-12')
...
sorted_doc_data = jschon_tools.process_json_doc(
schema_data=schema_data,
doc_data=doc_data,
sort=True,
)
Example
Given schema:
{
"type": "object",
"properties": {
"range": {
"type": "object",
"properties": {
"start": {"type": "number"},
"end": {"type": "number"}
}
}
}
}
the following document:
{"range": {"end": 20, "start": 10}}
would be reordered as:
{"range": {"start": 20, "end": 10}}
Metadata
Release files for jschon-sort 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| jschon-sort-0.2.0.tar.gz | 5.6 kB | Without provenance | Details for jschon-sort-0.2.0.tar.gz |
Release files / jschon-sort-0.2.0.tar.gz
| Download URL | jschon-sort-0.2.0.tar.gz |
|---|---|
| Size | 5.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
00794b5ecf01d15cc37cf1e72d305354ac8107ca6016fe8b7786e4d4055ac7ca
|
|
BLAKE2b-256 checksum How to use checksums |
82b0afff8e9c96afd9135223e7518423f92b244b01c0e27bd658dc36f0611328
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.13
|
Security for jschon-sort 0.2.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.