Skip to content

Instantly share code, notes, and snippets.

@yinleon
Created March 12, 2018 21:45
Show Gist options
  • Save yinleon/694fa2b2bc1b68975b3b1f8fc429fc1e to your computer and use it in GitHub Desktop.
Save yinleon/694fa2b2bc1b68975b3b1f8fc429fc1e to your computer and use it in GitHub Desktop.
A function to traverse and list all keys in a JSON or Dictionary
def get_all_keys(d, key=[]):
'''
A recursive function that traverses json keys in a dict `d`,
and prints the path to all keys
'''
if not isinstance(d, dict):
print(''.join(['["' + k + '"]' for k in key]))
return
for k, v in d.items():
key_path = key + [k]
get_all_columns(d[k], key_path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment