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
File details
Details for the file prettierjson-1.0.1.tar.gz
.
File metadata
- Download URL: prettierjson-1.0.1.tar.gz
- Upload date:
- Size: 5.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.13 CPython/3.9.2 Darwin/21.5.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 865e8ae320a4de93cc311e0d1fa9f60ccf8cf357bceb62ae28518c2b57300f2e |
|
MD5 | 045ab1fbbf8dd0e6a634a9eb2143f96c |
|
BLAKE2b-256 | 9ba151f97f213e72d1e1c2dea9362d62965b6ac96ce42e804dce1a9fa84bfb58 |
File details
Details for the file prettierjson-1.0.1-py3-none-any.whl
.
File metadata
- Download URL: prettierjson-1.0.1-py3-none-any.whl
- Upload date:
- Size: 6.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.13 CPython/3.9.2 Darwin/21.5.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 39f18883d4369685697f7319d94f4a73256b49f0eadd935f56837fba3cc93005 |
|
MD5 | c0d4b326c84512a7c59de1edea03b6d4 |
|
BLAKE2b-256 | 616c76d5d57e6e37c212ac21041947aee3722f391fc228c2d02a830e4435688f |