Last active
July 23, 2016 11:41
-
-
Save chiral/bd87f884e15be8e538f89c3d2df6b2f1 to your computer and use it in GitHub Desktop.
json viewer which can show unicode and top level array
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
# redirect to stdin to use | |
# % python show_jsons.py < hoge.json | |
import sys | |
import json | |
import pprint | |
lines = sys.stdin.readlines() | |
data = json.loads(''.join(lines),'utf8') | |
p = sys.stdout.write | |
def traverse(d,indent): | |
if type(d)==type({}): | |
print '{' | |
for k in d: | |
p(''.join([' ']*indent)+k+' : ') | |
traverse(d[k],indent+1) | |
print ',' | |
p('}') | |
elif type(d)==type([]): | |
p('[') | |
for i in range(len(d)): | |
p(''.join([' ']*indent)) | |
traverse(d[i],indent+1) | |
p(',') | |
p(']') | |
else: | |
if type(d)==type(u''): | |
p('"'+d.strip()+'"') | |
else: | |
p(unicode(d).strip()) | |
traverse(data,0) | |
print '' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment