Programming · Grade 11 · Chapter 9
Working with Data (JSON, Files)
Making sense of real-world data formats.
Here's a problem
A File Full of Curly Braces
A student opens a data file from an API response and sees a wall of curly braces, colons, and brackets. It looks intimidating — but it's actually a structured, readable format once you know the pattern.
Discuss before revealing: Does the structure remind you of anything we've already used in Python — like a dictionary?
Today's tool
JSON and File Reading
JSON (JavaScript Object Notation) is a widely-used data format that looks almost exactly like Python dictionaries. Most APIs return data in JSON — learning to read and parse it is essential.
How it looks
Reading JSON in Python
# reading and parsing JSON
import json
with open("data.json") as f:
data = json.load(f)
print(data["name"])
Let's build it together
Parse a Real JSON Dataset
We'll read and parse a small JSON dataset, extracting specific values from it.
Activity: Provide a small sample JSON file. Live-code loading it and extracting specific fields. Students type along and try accessing different values.
Quick check
What format does JSON data resemble?
AA single number
BA Python dictionary (key-value pairs)
BAn image file
DA sound file
Click to reveal answer
Let's discuss
Where might your capstone project need to work with JSON data?
If your project connects to an API, what kind of data might come back, and how would you use it?
Before you go
Today we learned...
JSON is the common language of data exchange between programs. Next week: fetching live data from real APIs!