The missing Python utility to read and write large compressed JSONs.
Maintained. Last release 2 weeks ago, commits in 2 of the last 26 weeks. Weaker on commit activity and release cadence.
pip install compress-jsoncompress_json
The missing Python utility to read and write compressed JSONs.
The library is loosely based on the compress_pickle library.
How do I install this package?
As usual, just download it using pip:
pip install compress_json
Available compression modes
The compression modes, detected automatically by the file name, are gzip, bz2, and lzma (or xz), with the notable exception of zip which seems difficult to integrate into the JSON pipeline.
Usage example
The library is extremely easy to use:
import compress_json
D = {
"A": {
"B": "C"
}
}
compress_json.dump(D, "filepath.json.gz") # for a gzip file
compress_json.dump(D, "filepath.json.bz") # for a bz2 file
compress_json.dump(D, "filepath.json.lzma") # for a lzma file
compress_json.dump(D, "filepath.json.xz") # for a lzma file
D1 = compress_json.load("filepath.json.gz") # for loading a gzip file
D2 = compress_json.load("filepath.json.bz") # for loading a bz2 file
D3 = compress_json.load("filepath.json.lzma") # for loading a lzma file
D3 = compress_json.load("filepath.json.xz") # for loading a lzma file
If it happens that you have to load or dump a JSON object with a custom extension, you can specify the compression mode by passing the compression parameter to the load and dump methods:
import compress_json
D = {
"A": {
"B": "C"
}
}
compress_json.dump(D, "filepath.custom_extension1", compression="gzip") # for a gzip file
compress_json.dump(D, "filepath.custom_extension2", compression="bz2") # for a bz2 file
compress_json.dump(D, "filepath.custom_extension3", compression="lzma") # for a lzma file
D1 = compress_json.load("filepath.custom_extension1", compression="gzip") # for loading a gzip file
D2 = compress_json.load("filepath.custom_extension2", compression="bz2") # for loading a bz2 file
D3 = compress_json.load("filepath.custom_extension3", compression="lzma") # for loading a lzma file
assert D == D1 == D2 == D3