I would like to grab some values within a JSON object using Python and assign them to variables for further use in the html frontend.
I tried it using the w3c resource and by googling but I can't get any successful print:
import requests
import json
response = requests.get("https://www.api-football.com/demo/api/v2/teams/team/33")
team_data = response.json()
team_name = team_data.teams.name
print(team_name)
This is the JSON Object i get from the external API:
{
"api": {
"results": 1,
"teams": [
{
"team_id": 33,
"name": "Manchester United",
"code": "MUN",
"logo": "https://media.api-football.com/teams/33.png",
"country": "England",
"founded": 1878,
"venue_name": "Old Trafford",
"venue_surface": "grass",
"venue_address": "Sir Matt Busby Way",
"venue_city": "Manchester",
"venue_capacity": 76212
}
]
}
}
The debug console tells me AttributeError: 'dict' object has no attribute 'teams'