Skip to content

clarketm/pprintjson

Folders and files

NameName
Last commit message
Last commit date
Sep 14, 2021
Apr 19, 2020
Apr 19, 2020
Nov 5, 2018
Sep 8, 2018
Jan 15, 2019
Sep 7, 2018
Dec 24, 2018
Aug 4, 2020
Feb 11, 2019
Aug 4, 2020
Sep 8, 2018
Aug 4, 2020
Aug 4, 2020

Repository files navigation

PyPi release PyPi versions Downloads Documentation Status

A json pretty printer for Python 🐍.

Check out the pprintjson docs

Installation

Install with the standard json JSON encoder

$ pip install pprintjson

Install with the premier simplejson JSON encoder

$ pip install pprintjson[simplejson]

Usage


usage: pprintjson.py [-h] [-i num] [-o file] [-c cmd] [-v] [file]

A pretty-printing function for json.

positional arguments:
  file                    json <file> to pretty-print

optional arguments:
  -h, --help              show this help message and exit
  -i num, --indent num    indent <num> number of spaces at each level (default: 4)
  -o file, --output file  write output to <file> instead of stdout (default: stdout)
  -c cmd, --command cmd   json <cmd> to pretty-print
  -v, --version           show program's version number and exit

Script

Pretty print JSON from a file using the pprintjson CLI.

$ pprintjson "./path/to/file.json"

Pretty print JSON from a stdin using the pprintjson CLI.

$ echo '{ "a": 1, "b": "string", "c": true }' | pprintjson

Pretty print JSON from a string using the pprintjson CLI.

$ pprintjson -c '{ "a": 1, "b": "string", "c": true }'

Pretty print JSON from a string with an indent of 1.

$ pprintjson -c '{ "a": 1, "b": "string", "c": true }' -i 1

Pretty print JSON from a string and save output to a file output.json.

$ pprintjson -c '{ "a": 1, "b": "string", "c": true }' -o ./output.json

Module

Pretty print JSON from a dict using the pprintjson module.

# 1. import the "pprintjson" function.
from pprintjson import pprintjson as ppjson

# 2. pretty print JSON.
obj = { "a": 1, "b": "string", "c": True }

ppjson(obj)

stdout

License

MIT Β© Travis Clarke