Skip to content

Instantly share code, notes, and snippets.

@filipsalomonsson
Created May 20, 2011 12:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save filipsalomonsson/982839 to your computer and use it in GitHub Desktop.
Save filipsalomonsson/982839 to your computer and use it in GitHub Desktop.
Simple JSON pretty-printer
#!/usr/bin/env python
# Copyright 2011 Filip Salomonsson <filip.salomonsson@gmail.com>
# MIT Licensed
# Simple JSON pretty-printer
# Save as ~/bin/json and pipe stuff to it.
import json
import sys
src = sys.stdin.read()
try:
json.dump(json.loads(src), sys.stdout, indent=2)
sys.stdout.write("\n")
except ValueError:
sys.stdout.write(src)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment