1. Concept library
  2. Python Foundations
  3. Module 10: Working with APIs

Concept

JSON data

JSON is the text format most APIs speak. json.loads turns it into dicts and lists; json.dumps goes the other way. The nesting in the text becomes nesting in your data.

What a session covers

The tutor works through these with you, in conversation and code. A session ends when you have shown them, not when a video does.

  1. Explain how JSON objects and arrays map to Python dicts and lists
  2. Parse a nested JSON response and pull out a value several levels down
  3. Serialise Python data to JSON and explain which types cannot be serialised

In practice

A few lines that show JSON data doing its job.

Python
import json

text = '{"user": {"name": "Ada", "tags": ["math", "code"]}}'
data = json.loads(text)
print(data["user"]["tags"][0])        # math

data["user"]["active"] = True
print(json.dumps(data, indent=2))

The common mistake

Watch for

Assuming a key is always present and at the expected depth. API responses change shape on errors and edge cases, so use get() for optional fields and check the status first.

What to know first

Your roadmap puts these before JSON data, unless you already know them.

How it stays learned

Once a session shows you understand JSON data, it comes back for review. Each review takes a minute and tells the memory model how well you still know it.

  1. Day 3First recall, while it is fresh
  2. Day 7Second, a week on
  3. Day 18Last, when it has settled
Previous in the module← HTTP requests
Next in the moduleHandling API errors →