Using python, Trying to parse through every key value within the dictionary. I was able to parse key value where the value is in turn another dictionary. But I'm now stuck at a point to parse a list within that inner dictionary. Below is the JSON structure.
json_struct = {
"Name":"John",
"Age":"30",
"State":"NC",
"xxxx":{
"xxxx1":"1111111",
"xxxx2":"222222",
"xxxx3":[
{
"aaa1": "333",
"aaa2":"444"
},
{
"bbb1": "555",
"bbb2":"666"
}
]
}
}
Code piece doing the iteration:
def check1(json_struct):
for k, v in json_struct.items():
if isinstance(v, OrderedDict):
check1(v)
else:
print "{0} : {1}".format(k, v)
Actual Output:
Name:John
Age:30
state:NC
xxxx1:1111111
xxxx2:222222
xxxx3:[('aaa1','333'), ('aaa2':'444'), ('bbb1:555'), ('bbb2:666')]
Expected Output:
Name:John
Age:30
state:NC
xxxx1:1111111
xxxx2:222222
aaa1:333
aaa2:444
bbb1:555
bbb2:666
I'm missing something to iterate through the list i believe, but I tried the isinstance with list within the if as well, still the incorrect result is what I'm getting.
Any knowledge share on this will be highly appreciated.
Thanks in advance!