Generate prettier and more compact JSON dumps
Project description
prettierjson
Generate prettier and more compact JSON dumps
Installation
prettierjson can be installed using one of these commands:
pip install prettierjson
poetry add prettierjson
Usage
in python scripts
prettierjson offers one function prettierjson.dumps()
which is intended to be used as a drop-in replacement for json.dumps()
from prettierjson import dumps
my_dictionary = {"foo": bar}
with open("foobar.json", "w") as f:
f.write(dumps(my_dictionary))
If prettierjson needs to exist within the same module as the built-in json package without overriding the default json.dumps()
, the entire package should be imported in order to avoid namespace collisions
import json
import prettierjson
my_dictionary = {"foo": bar}
with open("builtin.json", "w") as f:
f.write(json.dumps(my_dictionary))
with open("prettierjson.json", "w") as f:
f.write(prettierjson.dumps(my_dictionary))
See the documentation for more details.
as a command line interface
prettierjson has a __main__
module which allows it to be called directly when installed with the command python -m prettierjson
.
In this way, prettierjson can be used to "prettify" one or multiple JSON files in-place by passing them as arguments
$ python -m prettierjson PATH/TO/JSON/FILE1.json PATH/TO/JSON/FILE2.json
Indent size and max line length can be set with the --indent
and --line-length
flags
$ python -m prettierjson --indent=2 --line-length=88 PATH/TO/JSON/FILE.json
Run python -m prettierjson -h
for more command line usage details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for prettierjson-1.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 39f18883d4369685697f7319d94f4a73256b49f0eadd935f56837fba3cc93005 |
|
MD5 | c0d4b326c84512a7c59de1edea03b6d4 |
|
BLAKE2b-256 | 616c76d5d57e6e37c212ac21041947aee3722f391fc228c2d02a830e4435688f |