def get_leaves(item, key=None):
    """ Idea taken from https://stackoverflow.com/questions/41180960/convert-nested-json-to-csv-file-in-python """ 
    if isinstance(item, dict):
        leaves = []
        for i in item.keys():
            leaves.extend(get_leaves(item[i], i))
        return leaves
    elif isinstance(item, list):
        leaves = []
        for i in item:
            leaves.extend(get_leaves(i, key))
        return leaves
    else:
        return [(key, item)]