Reading JSON data from an API response
Converts the JSON text of an API response into Python dictionaries and lists, so you can read values by key, e.g. data['name'], or loop over a list of results.
Understanding Reading JSON data from an API response in VCE Software Development U4O1
What it does: The 'results' key holds a list of dictionaries, so a for loop visits each one and reads its 'title' key. The response object must be converted with response.json() first, then data holds dictionaries and lists that can be read by key. Use square brackets with the key as a string. Round brackets would try to call data as a function. json() is a method, so it needs brackets. Without them you only get the method itself, not the parsed data. Accessing a key returns just the value stored under it, here the string 'Mia', not the whole dictionary. Once response.json() has produced a dictionary, you access a value by putting its key in square brackets.
Common mistakes: response.json() gives a dictionary, and dictionary values are read by key with square brackets. Dot notation does not work on a dictionary. It should be print(data['name']). json is a method, so it needs brackets to run. Without them, data just holds the method itself instead of the dictionary. It should be data = r.json().
Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.
This module's key terms are also in a printable crossword (Modules 115–124) and word search (Modules 115–171).
Take this worksheet further — free with Cloodit
Each concept is reinforced from every angle — learned, then applied, then tested.
Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.
Over 100 of them, across seven natural biomes.
Turns their work into revision material ready for Flash Cards and Exam study.
Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.
Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.
Quick Questions
Match the Pairs
Key Term
response.json()Fill in the Blanks
Spot the Error
Student with a class code? Join your class →