condense-json
Python function for condensing JSON using replacement strings
What it is and what it does
condense-json provides two functions to reduce JSON size by identifying and replacing repeated content. The `condense_json` function scans a JSON-like object for strings that contain replacement substrings, dicts and lists that match replacement structures exactly, and dicts that are close to a replacement base (stored as base plus a patch). Each match is replaced with a compact reference marker. The `uncondense_json` function reverses this, restoring the original JSON from the condensed form.
The package handles three reference types: whole-value matches (`{"$": id}`), strings containing multiple replacements (`{"$r": [segments]}`), and dicts stored as a base plus a patch. Matching is deterministic—longest substring wins when patterns overlap—and round-tripping is guaranteed: `uncondense_json(condense_json(obj, r), r) == obj` always holds. It requires Python 3.10+ and has no external dependencies.
Use it for:
- Reduce payload size when transmitting repetitive JSON (e.g., API responses with duplicate schemas or tool definitions).
- Compress JSON logs or structured data with common patterns to save storage or bandwidth.
- Deduplicate embedded JSON blobs that appear in multiple places with minor variations.
- Minimize JSON sent to language models or other services where token count or size matters.
- Archive or cache JSON while preserving exact round-trip fidelity.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Condense JSON by replacing repeated strings and structural patterns with compact references, then expand them back to their original form.
Yes. The package is lightweight, actively maintained, has no dependencies, and solves a specific problem well—reducing JSON size through deterministic pattern replacement with guaranteed round-tripping. The Apache-2.0 license is permissive. Install if you need to compress repetitive JSON or deduplicate structural patterns; skip if your JSON is already sparse or you need byte-identical serialization.
Install
condense-json on PyPI
pip
pip install condense-jsonuv
uv add condense-jsonpoetry
poetry add condense-jsonInstalling condense-json
Before you install
Low friction: pure Python wheel with no runtime dependencies. Active maintenance with recent release.
License in practice
Apache-2.0 permissive license allows commercial and private use with attribution.
Quickstart
pip install condense-json
from condense_json import condense_json, uncondense_json
obj = {"text": "hello world", "more": "hello again"}
replacements = {"1": "hello"}
condensed = condense_json(obj, replacements)
original = uncondense_json(condensed, replacements)
Requires Python 3.10 or later.
Verify before relying
- Typical compression ratio or size reduction achieved on real-world JSON payloads
- Performance characteristics with large JSON structures or many replacement patterns
- Whether merge references (base + patch) are commonly useful in practice
Package facts
| License | Apache-2.0 (permissive) |
| Python support | supports the current Python release (>=3.10) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | actively maintained — 11 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 456,382/month — #6,555 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: condense_json-1.1-py3-none-any.whl
Tags
More Utilities packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
charset-normalizerDetects and normalizes text encoding from…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
pluggyPluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
PygmentsPygments is a syntax highlighter that colorizes…
permissive · top 100 on PyPI
sixSix provides utility functions to write Python…
permissive · top 100 on PyPI
compact-jsonFormats JSON into compact, human-readable…
permissive · top 5,000 on PyPI
jsoncomparisonCompares two JSON-like objects and returns a…
permissive · top 5,000 on PyPI
flatten-jsonConverts nested JSON objects into flat…
permissive · top 5,000 on PyPI
flatdictFlattens nested dictionaries into single-level…
permissive · top 5,000 on PyPI
jsondiffComputes structured diffs between JSON and…
permissive · top 5,000 on PyPI
json-merge-patchMerges JSON objects according to RFC 7386 and…
permissive · top 5,000 on PyPI
pyjsonCompares the similarity between two JSON files…
permissive · top 15,000 on PyPI
deepmergeMerges nested Python data structures (dicts,…
permissive · top 5,000 on PyPI
jcsCanonicalizes JSON according to RFC 8785,…
permissive · top 5,000 on PyPI
mo-dotsProvides null-safe dot-notation access to…
copyleft · top 15,000 on PyPI