browse a dynamic json that contains nested lists and dictionaries

Easy solution, you really need only a simple recursion if i get it right

full_dict = mass_upt_res_data_json["mass_update"]

def check_inst(elem):
    for e in elem:
        if isinstance(e, list):
            print("list reached")
            check_inst(e)
        else:
            for key, value in e.items() :
                print (key, value)

check_inst(full_dict)

prints:

lvl-1 lvl-1.1
lvl-1 lvl-1.2
lvl-1 lvl-1.3
list reached
lvl-2 lvl-2.1.2
list reached
lvl-3 lvl-3.1
lvl-3 lvl-3.2
list reached
lvl-4 lvl-4.1.2
lvl-4 lvl-4.2.2
lvl-2 lvl-2.2.2
list reached
lvl-3 lvl-3.3
lvl-3 lvl-3.4
list reached
lvl-4 lvl-4.3.2
lvl-4 lvl-4.4.2

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top