Skip to content

Instantly share code, notes, and snippets.

@narate
Last active September 30, 2016 00:06
Show Gist options
  • Save narate/2f88b7737cf8b40dc8ac to your computer and use it in GitHub Desktop.
Save narate/2f88b7737cf8b40dc8ac to your computer and use it in GitHub Desktop.
Pretty print JSON from stdin. Code base from @aborigines [https://github.com/aborigines]. Base on this story on facebook -> https://www.facebook.com/koonnarate/posts/10202501031914513
#!/usr/bin/python
import sys
import json
data = sys.stdin.read()
json_data = json.loads("".join(data))
json_string = json.dumps(json_data, sort_keys=True, indent=4, ensure_ascii=False)
print(json_string)
{"th" : { "message": "สวัสดี" },"en" : { "message" : "hello" }}
@narate
Copy link
Author

narate commented Sep 2, 2014

Example
$ curl -s https://gist.githubusercontent.com/narate/2f88b7737cf8b40dc8ac/raw/8cfbc66db1a16e28dcf9053102b5e2c550ecce61/test.json | pretty_json.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment