Skip to main content

Generate prettier and more compact JSON dumps

Project description

prettierjson

made-with-python Code style: black Github release PyPi Documentation

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

prettierjson-1.0.1.tar.gz (5.7 kB view hashes)

Uploaded Source

Built Distribution

prettierjson-1.0.1-py3-none-any.whl (6.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page