Skip to content

Instantly share code, notes, and snippets.

@pwc3 pwc3/ppjson
Last active May 11, 2020

Embed
What would you like to do?
Pretty-Print JSON
#!/usr/bin/env python
from __future__ import print_function
import sys
import json
try:
json.dump(json.load(sys.stdin), sys.stdout, sort_keys=True, indent=4)
except ValueError as err:
print("Error:", err, file=sys.stderr)
exit(1)
@pwc3

This comment has been minimized.

Copy link
Owner Author

pwc3 commented Apr 13, 2020

Pretty-prints JSON via the terminal. Reads input only from stdin.

To format JSON on the clipboard:

$ pbpaste | ppjson

To format JSON in a file:

$ ppjson < filename
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.