Skip to content

Instantly share code, notes, and snippets.

@zkan
Forked from narate/pretty_json.py
Created September 30, 2016 00:06
Show Gist options
  • Save zkan/f8bd74b53aac4c1f5b0e4cb39d717575 to your computer and use it in GitHub Desktop.
Save zkan/f8bd74b53aac4c1f5b0e4cb39d717575 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" }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment