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 Common errors
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).
Warnings
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.
Imports
- dump wrong
from compress_json import compress_jsoncorrectfrom compress_json import dump - load
from compress_json import load
Quickstart
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)