compress-json

raw JSON →
1.1.1 verified Fri May 01 auth: no python

The missing Python utility to read and write large compressed JSONs. Supports automatic compression detection from file extensions (gzip, bz2, lzma, xz) or explicit specification. Current version 1.1.1, active development with periodic releases.

pip install compress-json
error Expected a dictionary or list, got str
cause Calling dump(path, data) instead of dump(data, path).
fix
Swap arguments: from_compress_json import dump; dump(my_data, 'file.json.gz')
error ValueError: Unsupported file extension
cause Using an uncommon extension like .json.lz or no extension without specifying compression parameter.
fix
Add compression='lzma' (or other) to dump/load, or use a standard extension (.gz, .bz2, .xz, .lzma).
gotcha Argument order: dump(data, path) not dump(path, data). Swapping arguments raises ValueError: 'Expected a dictionary or list, got str'.
fix Always provide data first, then file path.
gotcha File extension must match actual compression or pass compression argument explicitly; otherwise, function may misinterpret format.
fix Use compression='gzip' (or 'bz2', 'lzma', 'xz') when extension is missing or does not match.

Basic usage: dump serializes to a compressed JSON file, load reads it back. Compression type is inferred from file extension (.gz, .bz2, .xz, .lzma).

from compress_json import dump, load

data = {"key": "value"}
# Save to file (extension determines compression)
dump(data, "data.json.gz")
# Load back
loaded = load("data.json.gz")
print(loaded)