Created
August 10, 2011 19:29
-
-
Save mvanveen/1137900 to your computer and use it in GitHub Desktop.
This file contains 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
# -*- coding: utf-8 -*- | |
'''' | |
NOTE: on dev_appserver.py console needs a cast to a dict() like so: | |
pending_dict = dict(pending_activity) | |
sometimes datatype passed back up to the method for recursing is not an array or a dict, but a float, say | |
which has no len() method and raises TypeError, thus the try except block | |
''' | |
import json | |
def print_list_dict(indent, myinput): | |
if isinstance(myinput, list): | |
for e in myinput: | |
if not isinstance(e, dict): | |
print '%s%s' % (indent, str(e).encode('ascii', 'ignore')) or print_list_dict(indent,e) | |
else: | |
print_list_dict(indent, e) | |
elif isinstance(myinput, dict): | |
for k, v in myinput.iteritems(): | |
if isinstance(v, dict) or isinstance(v, list): | |
print ("%s%s: " % (indent, str(k).encode('ascii', 'ignore'))) | |
print_list_dict(" " + indent, v) | |
if isinstance(v, dict): | |
else: | |
print ("%s%s: %s" % ( | |
indent, | |
str(k).encode('ascii', 'ignore'), | |
str(v).encode('ascii', 'ignore')) | |
) | |
if __name__ == '__main__': | |
import sys | |
with open(sys.argv[1], 'r') as fileObj: | |
dictObj = json.loads(fileObj.read()) | |
print_list_dict("", dictObj) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment