Adds FracturedJSON support to python, letting you create JSON that is both compact and readable.
You can trivially use it as a drop-in replacement for the built-in json module:
import fracturedjson as json
long_list = [f"thing_{i}" for i in range(20)]
data = {"abcd": "abcd", "long_list": long_list}
print(json.dumps(data))
print(json.dumps(data, line_length=50))
print(json.dumps(data, indent=2))
with open("file.json", "w") as f:
json.dump(data, f)
with open("file.json") as f:
json.load(f)
json.loads('{"foo":"bar"}')Or, if you'd prefer:
import json
from fracturedjson import Encoder
long_list = [f"thing_{i}" for i in range(20)]
data = {"abcd": "abcd", "long_list": long_list}
print(json.dumps(data, cls=Encoder))
print(json.dumps(data, cls=Encoder, line_length=50))
print(json.dumps(data, cls=Encoder, indent=2))
with open("file.json", "w") as f:
json.dump(data, f, cls=Encoder)This is largely a wrapper around fracturedjson-rs, so credit to the creator.