Skip to content

Instantly share code, notes, and snippets.

@chiral
Last active July 23, 2016 11:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chiral/bd87f884e15be8e538f89c3d2df6b2f1 to your computer and use it in GitHub Desktop.
Save chiral/bd87f884e15be8e538f89c3d2df6b2f1 to your computer and use it in GitHub Desktop.
json viewer which can show unicode and top level array
# 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