🐸

The Scroll of Records

The Data Tinkererpython-data-tinkerer-22-the-scroll-of-records
Reward: 120 XP
|

The Scroll of Records

Hoppy opens the first drawer in the data cabinet and finds a real record scroll waiting inside. This time the information is not written as loose text and it is not hidden inside a function. It is stored as JSON: a tidy format for structured records.

Today we only do two small things. First, we learn to look at a JSON file and recognize its shape. Then we read a few simple fields from it, almost the same way we would read values from a Python dict.

JSON often looks very close to Python dict and list shapes

A JSON record is just data arranged in a clear structure. When you see curly braces { ... }, you are usually looking at an object shape that feels a lot like a Python dict. When you see square brackets [ ... ], you are looking at a list-like shape.

{
"scroll_title": "Lantern Arrival Log",
"seal_count": 3
}

["lantern", "moon", "fern"]

You do not need to memorize a big theory here. The helpful first impression is simply this: JSON is a way to store structured data, and once Python loads it, the shape often feels very familiar.

Today: load one flat JSON record and read a few top-level fields

The real starter already handles the file-loading step. Before you touch that real record, it helps to practice the smaller motion on a toy object that already looks like loaded JSON: read a couple of named fields with square brackets.

camp_note = {
  "camp_name": "Moss Lantern Camp",
  "guide": "Pip",
  "day_count": 2
}

camp_name = camp_note["camp_name"]
guide = camp_note["guide"]

print("Camp name:", camp_name)
print("Guide:", guide)

That is the exact reading motion you need today. Once Python has already loaded a JSON file into a variable, you are just pulling values out by key. In the real task, you will do that on the starter's record and read three fields, but this toy example keeps the file details out of the way so the core move stays clear.

1
Keep the loaded JSON record visible

The starter already reads scroll_record.json and prints scroll_record. Run it and take one moment to notice the whole shape before pulling out any pieces.

2
Read three simple fields by key

Set scroll_title, keeper_name, and seal_count by reading them from scroll_record with square brackets.

3
Compare the whole record with the smaller values

When you run the code, you should see the full record first and the three extracted fields after it. That is the core move for this lesson: see the record's shape, then read a few named parts.

Keep the boundary narrow

This first JSON lesson is only about recognizing the shape of a structured record and reading simple top-level fields. We are not moving into APIs, JSON schema, or deeper nested paths yet.

Suggested Solution
Expand
Solution:
import json

with open("scroll_record.json", "r", encoding="utf-8") as file:
  scroll_record = json.load(file)

print("Scroll record:", scroll_record)

scroll_title = scroll_record["scroll_title"]
keeper_name = scroll_record["keeper_name"]
seal_count = scroll_record["seal_count"]

print("Scroll title:", scroll_title)
print("Keeper name:", keeper_name)
print("Seal count:", seal_count)
Advanced Tips
Want more? Click to expand

The important win today is not memorizing the json module. It is building a calm first instinct: a JSON file can simply be a structured record with named fields that you can read one by one.

In the next lesson, the record shape can become a little deeper. For now, staying with one flat file and three easy field lookups is exactly enough.

Loading...
Terminal
Terminal
Ready to run...