Skip to content

Instantly share code, notes, and snippets.

@shomah4a
Created April 7, 2020 08:01
Show Gist options
  • Save shomah4a/674f0cd889d8701909282c8ef0c7d096 to your computer and use it in GitHub Desktop.
Save shomah4a/674f0cd889d8701909282c8ef0c7d096 to your computer and use it in GitHub Desktop.
import json
import sys
def p(key, indent):
print('%s%s' % (' ' * (indent*2), key))
def print_object(obj, indent=0):
if isinstance(obj, dict):
items = sorted(list(obj.items()), key=lambda x: x[0])
for k, v in items:
p('- %s' % k, indent)
print_object(v, indent+1)
elif isinstance(obj, list):
if len(obj) > 0:
p('[', indent)
print_object(obj[0], indent+1)
p(']', indent)
else:
p('[]', indent)
if __name__ == '__main__':
for f in sys.argv[1:]:
with open(f) as fp:
obj = json.loads(fp.read())
print_object(obj)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment