Skip to content

Instantly share code, notes, and snippets.

@mossprescott
Created November 25, 2015 00:16
Show Gist options
  • Select an option

  • Save mossprescott/0bb9038dfd5acc8bdb2e to your computer and use it in GitHub Desktop.

Select an option

Save mossprescott/0bb9038dfd5acc8bdb2e to your computer and use it in GitHub Desktop.
Command-line pretty-priner for JSON (one value, can be multi-line)
#! /usr/local/bin/python
# Slightly modified from the module's own __main__ behavior (according to the interwebs).
import sys, json
infile = sys.stdin
outfile = sys.stdout
with infile:
obj = json.load(infile)
with outfile:
json.dump(obj, outfile, indent=2, separators=(',', ': '))
outfile.write('\n') # final newline for usability in the shell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment