I have a json that looks like this:
[
{
"status":"passed",
"elements":[{"name":"foo"},{"name":"bar"}]
},
{
"status":"failed",
"elements":[{"name":"foo1"},{"name":"bar1"}]
}
]
I am trying to iterate through the elements array:
for a in json['elements']:
print a['name']
I get this error:
TypeError: list indices must be integers, not str
My python is really bad. Thank you
json['elements']gives you a list of two items:{"name":"foo1"}, and {"name":"bar1"}, so you need to index into it with an integer, not a string.