Created
July 11, 2018 15:51
-
-
Save colehocking/f8e07e20c0b802288b568a9cb5824de0 to your computer and use it in GitHub Desktop.
dumpClean: the mighty nested JSON object expander!
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
def dumpClean(obj): | |
""" | |
Recursive function to clean the output of deeply nested dicts/lists | |
""" | |
if type(obj) == dict: | |
for k, v in obj.items(): | |
# if the object has an iterable attribute; keep pulling it apart | |
if hasattr(v, '__iter__'): | |
print("%s : %s" % (k, dumpClean(v))) | |
else: | |
print('%s : %s' % (k, v)) | |
elif type(obj) == list: | |
for o in obj: | |
if hasattr(o, '__iter__'): | |
dumpClean(o) | |
else: | |
print("%s" % (str(o))) | |
else: | |
print(str(obj)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment