--- id: condense-json version: "1.1" license: Apache-2.0 license_treatment: permissive maintenance: active --- # condense-json — Python function for condensing JSON using replacement strings License: permissive · Maintenance: active · Downloads: 456.4K/mo ## 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 above — 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 pip install condense-json uv add condense-json poetry add condense-json ## Installing 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_current - Install friction: low - Maintenance: active - Downloads: 456.4K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags json compression deduplication, reduce json size, json string replacement, compact json encoding, json pattern matching, minimize json payload, json structural deduplication, json-compression, data-deduplication [View on SkillFed](https://skillfed.io/packages/condense-json) · [View on PyPI](https://pypi.org/project/condense-json/)