I have a JSON file which is a tuple of multiple dictionaries and I want to extract keys and values from some of them.
The file looks something like this (this is just an example of the structure with random keys and values):
file =
[
{
"element": {
"name": "Ana",
"bio": "xx",
"type": "female"
},
"ID": "1234",
"status": "STOPPED"
},
{
"element": {
"name": "Bob",
"bio": "xy",
"type": "male"
},
"ID": "5678",
"status": "STOPPED"
},
{
"element": {
"name": "Chloe",
"bio": "xx",
"type": "female"
},
"ID": "8912",
"status": "STOPPED"
}
]
What I want to extract all names (Ana, Bob, Chloe) and their ids something like this:
Ana = 1234,
Bob = 5678
etc.
Whatever that I have already tried gives back attribute errors etc. I am not even sure how to iterate through this correctly so that it takes name
and ID
because they don't have the same location (the name
is inside element
dict).
I even tried converting the file to list.