Reduces JSON, YAML, and NDJSON volume by collapsing repeated structures while preserving the schema.
Project description
JSON's Razor — Cut the fat
Reduces JSON, YAML, and NDJSON volume by collapsing repeated structures while preserving the schema.
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 |
Project details
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_razor-0.1.2.tar.gz.
File metadata
- Download URL: json_razor-0.1.2.tar.gz
- Upload date:
- Size: 4.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
193aa7307817036809f822326f1f857bb229a9c0b6511a559733fcec075792f6
|
|
| MD5 |
d00973342e4c2e0c2afb23f1f0c68dc6
|
|
| BLAKE2b-256 |
984ffb7ef80a690b3dfa1568e0458d60cc7f6f8a2f8cad6ba2ffd82e369aac8f
|
Provenance
The following attestation bundles were made for json_razor-0.1.2.tar.gz:
Publisher:
release.yml on rick-does/json-razor
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
json_razor-0.1.2.tar.gz -
Subject digest:
193aa7307817036809f822326f1f857bb229a9c0b6511a559733fcec075792f6 - Sigstore transparency entry: 1280924184
- Sigstore integration time:
-
Permalink:
rick-does/json-razor@a3f123d7b1fdcbfe621d14cb6a379d41d5eff94b -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/rick-does
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@a3f123d7b1fdcbfe621d14cb6a379d41d5eff94b -
Trigger Event:
push
-
Statement type:
File details
Details for the file json_razor-0.1.2-py3-none-any.whl.
File metadata
- Download URL: json_razor-0.1.2-py3-none-any.whl
- Upload date:
- Size: 4.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
07a61fbfe9a383a06e58fdadbd955ac5f01c7b6ee52f7bba6481e89414341fab
|
|
| MD5 |
75b03c1f657a178d0cc54c8faae94bb1
|
|
| BLAKE2b-256 |
313c917c5b6bcd0cb658d37a8eb17ad8a4b5ef6922de2ce53b82394e4a8d86ea
|
Provenance
The following attestation bundles were made for json_razor-0.1.2-py3-none-any.whl:
Publisher:
release.yml on rick-does/json-razor
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
json_razor-0.1.2-py3-none-any.whl -
Subject digest:
07a61fbfe9a383a06e58fdadbd955ac5f01c7b6ee52f7bba6481e89414341fab - Sigstore transparency entry: 1280924195
- Sigstore integration time:
-
Permalink:
rick-does/json-razor@a3f123d7b1fdcbfe621d14cb6a379d41d5eff94b -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/rick-does
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@a3f123d7b1fdcbfe621d14cb6a379d41d5eff94b -
Trigger Event:
push
-
Statement type: