JSON's Razor — Cut the fat
Reduces JSON, YAML, and NDJSON volume by collapsing repeated structures while preserving the schema, making the schema easier for you to read.
Large structured data files are hard to parse — not because the structure is complex, but because repetition obscures it. A list of 10,000 objects with identical shape tells you nothing more than a list of 1. JSON's Razor collapses that repetition to its minimum essential form: one representative example of each repeated structure, at every level of nesting.
The output is valid, parseable data in the same format as input — not a summary, not a schema definition. It just has far less volume.
Install
pip install json-razor
Usage
cat big.json | json-razor # stdin → stdout
json-razor big.json # file input → stdout
json-razor big.json -o small.json # file input → file output
json-razor big.yaml # auto-detected as YAML
json-razor app.log --format ndjson # NDJSON log file
Options
| Flag | Default | Description |
|---|---|---|
--keep N |
1 | Number of examples to keep per repeated structure |
--depth N |
unlimited | Stop collapsing below this nesting depth |
--format |
auto | Force format: json, yaml, or ndjson |
--truncate N |
100 | Max string length before truncating |
How it works
Arrays — collapsed to one item. Mixed-type arrays keep one of each distinct type.
// input
[{"id": 1, "name": "alice"}, {"id": 2, "name": "bob"}, {"id": 3, "name": "carol"}]
// output
[{"id": 1, "name": "alice"}]
Mixed types — one representative per JSON type (null, bool, number, string, array, object).
// input
[1, "hello", {"id": 1}, null, true, [1, 2, 3]]
// output
[1, "hello", {"id": 1}, null, true, [1]]
Nested structures — collapsed recursively at every level.
NDJSON — collapsed across lines; one representative line kept.
Nulls and empty values — always preserved (null, [], {}).
Long strings — truncated to a configurable preview.
Supported formats
| Format | Auto-detected from |
|---|---|
| JSON | .json |
| YAML | .yaml, .yml |
| NDJSON | .ndjson |
Use case: OpenAPI specs
OpenAPI specs are a natural fit for JSON's Razor. They're long, deeply nested, and repeat the same response structures across dozens of endpoints.
Run the included sample to see it in action:
json-razor tests/samples/openapi.yaml
You get the full API shape — every path, method, status code, and referenced schema — without the repetition that obscures it. Useful for:
- Reviewing an unfamiliar API quickly
- Inspecting generated specs in CI before they're published
- Diffing structural changes between spec versions
Metadata
Release files for json-razor 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| json_razor-0.1.3.tar.gz | 4.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| json_razor-0.1.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 9.6 kB
Release files / json_razor-0.1.3.tar.gz
| Download URL | json_razor-0.1.3.tar.gz |
|---|---|
| Size | 4.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e59cd5cbbfe297fc5ee38dc1fdb926e973f238b845818c19cab5029625657a37
|
|
BLAKE2b-256 checksum How to use checksums |
59275bdef7fd24f13464bdad6a6c46d21250321da51c254497633455da0ea3eb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 20, 2026.
Transparency logRelease files / json_razor-0.1.3-py3-none-any.whl
| Download URL | json_razor-0.1.3-py3-none-any.whl |
|---|---|
| Size | 4.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3d7a7d67c9b1c2c8915940e65ebaf466e951b9d7c277c2dddf468ab6888a6fa5
|
|
BLAKE2b-256 checksum How to use checksums |
f14868a7711f45b57cd42fecd4569277fc047978cad1822cf25949ce16f43006
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 20, 2026.
Transparency log