Home > Mobile >  Loop over a JSON not picking up all values
Loop over a JSON not picking up all values

Time:06-03

I am trying to return each highlight's 'blurb' and 'FLASH_1800K_896x504' url. To do this, I am running this loop below:

import requests
game_url = "http://statsapi.web.nhl.com/api/v1/game/2021030321/content"
team_response = requests.get(game_url)
js = team_response.json()
newdata = js['highlights']['gameCenter']['items']
for item in newdata:
    print(item['blurb'])
    print(item['playbacks'][3]['url'])

After doing a Ctrl-F on the data file, I am expecting 51 results. However, only 15 are being returned. Am I missing something obvious?

CodePudding user response:

seems like not all occurence of "FLASH_1800K_896x504" exist in the path that you're logging, try exploring futher more your json file

  • Related