Created
September 6, 2013 23:55
-
-
Save dblackdblack/6471481 to your computer and use it in GitHub Desktop.
formatjson.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import fileinput | |
import json | |
import re | |
if __name__ == "__main__": | |
jsonStr = '' | |
for a_line in fileinput.input(): | |
jsonStr = jsonStr + ' ' + a_line.strip() | |
# strip any trailing semicolon so we can also format object literal statements | |
p = re.compile( ';\s*$' ) | |
jsonObj = json.loads(p.sub( '', jsonStr )) | |
print json.dumps(jsonObj, sort_keys=True, indent=2) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment