Skip to content

Instantly share code, notes, and snippets.

@pwc3
Last active May 11, 2020 00:57
Show Gist options
  • Save pwc3/849a6da2b20f6a1e8bc9c9288b143bf4 to your computer and use it in GitHub Desktop.
Save pwc3/849a6da2b20f6a1e8bc9c9288b143bf4 to your computer and use it in GitHub Desktop.
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
Copy link
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