I have dynamically changing json file (not the entire file changes dynamically, its just at one point which I will specify below) and I need to iterate using for loop at that point (where it changed dynamically) so that I can grab required elements inside that bracket in json file. Below is json snippet what it looks like.
"A" : {
"uni/aa/bb" (----> This changes randomly): [ {
"Name" : "cc",
"Id" : "1",
}, {
"Name" : "cc",
"Id" : "1",
} ]
}
I used re.search to match the pattern I get at that point. But no luck. I need to store Name and Id values ultimately. Any suggestions?
resp = json.loads(resp) ---> This gives me above mentioned json output
Here are the sample of codes I am trying.
for k in resp['A']:
for v in k['uni/aa/bb']: #---> TypeError: string indices must be integers
for k in resp['A']:
m = re.search('uni/(.*)') #--> Because this is changing dynamically
if m:
name = str(m['Name']) #---> TypeError: '_sre.SRE_Match' object has no attribute '__getitem__'