I have a JSON file and am trying to extract a list of all teams. I can do it with one iteration, but when it's nested at more than one level, I am unable to do anything. In this scenario, I am trying to extract players into a data frame and write that to json. Code is below. Starting with JSON. Thanks!
{
"teams": [{
"coach": "Cowher",
"players": [{
"player": "Simms",
"number": 11
}, {
"player": "Bradshaw",
"number": 12
}, {
"player": "Elway",
"number": 7
}]
}]
}
Here is my Python script.
response = urllib.urlopen(url)
data = json.loads(response.read())
df = items_data = pd.DataFrame**(data['teams']['players'])**
I know in the last line is where the error is and that this is a Series. How do I get all players. Once I get this I can write this to a csv. Any help will be greatly appreciated!