Last active
September 30, 2016 00:06
-
-
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
This file contains hidden or 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/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) |
This file contains hidden or 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
{"th" : { "message": "สวัสดี" },"en" : { "message" : "hello" }} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example
$ curl -s https://gist.githubusercontent.com/narate/2f88b7737cf8b40dc8ac/raw/8cfbc66db1a16e28dcf9053102b5e2c550ecce61/test.json | pretty_json.py