def fun(d):
    if 'id' in d:
        yield d['id']
for k in d:
    if isinstance(d[k], list):
        for i in d[k]:
            for j in fun(i):
                yield j
Find all occurences of a key in nested python dictionaries and lists