skillfed

condense-json

Python function for condensing JSON using replacement strings

condense-json v1.1 456.4K downloads/30d#6,555 on PyPI11
Permissive license Apache-2.0 Active released

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-json

uv

uv add condense-json

poetry

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 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

Typing :: Typed

Tags

json compression deduplicationreduce json sizejson string replacementcompact json encodingjson pattern matchingminimize json payloadjson structural deduplication
json-compressiondata-deduplication

More Utilities packages