Skip to content

Repository files navigation

pyFracturedJSON

Adds FracturedJSON support to python, letting you create JSON that is both compact and readable.

Dynamic JSON Badge Dynamic JSON Badge

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.

About

A compact yet readable formatter for python

Resources

Stars

4 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages