Return a list of all variable names in a python nested dict/json document in dot notation
I'm looking for a function that operates on a python arbitrarily nested dict/array in JSON-esque format and returns a list of strings keying all the variable names it contains, to infinite depth. So, if the object is... x = { 'a': 'meow', 'b': { 'c': 'asd' }, 'd': [ { "e": "stuff", "f": 1 }, { "e": "more stuff", "f": 2 } ] } mylist = f(x) would return... >>> mylist ['a', 'b', 'b.c', 'd[0].e', 'd[0].f', 'd[1].e', 'd[1].f'] def dot_notation(obj, prefix=''): if isinstance(obj, dict): if prefix: prefix += '.' for k, v in obj.items(): for res in dot_notation(v, prefix+str(k)): yield res elif