Good place to stop if you're short on time — step 3 picks up here.
Lesson idea Tap to fold
What does json.loads() return for a JSON object?
Show the answer
A Python dictionary.
JSONL means one document per line
Use splitlines to visit each line, then decode that line with json.loads. JSONL is not a single array; calling loads on the entire multiline batch fails. A triple-quoted Python string simply gives us multiline sample text.
These first exercises assume every nonempty line is a valid record with the named keys. They do not yet handle blank or malformed lines. Day 25 introduces an explicit audit policy instead of silently skipping failures. When writing JSONL, emit one JSON object per line without multiline indenting; compact or default spaces are both valid.
The worked example first appends each serialized row to a list. "\n".join(lines) inserts a newline between those strings to make one batch. The second loop decodes the batch again, preserving its order and numeric types.
# JSONL means one document per line.
import json
records = [
{"item_id": "Museum", "score": 1},
{"item_id": "Canal", "score": 5},
]
lines = []
for row in records:
lines.append(json.dumps(row))
text = "\n".join(lines)
for line in text.splitlines():
row = json.loads(line)
print(row["item_id"], "·", row["score"])
Museum · 1, then Canal · 5. Each line is decoded separately and each score remains an integer.
The loop preserves order. Empty text has no rows; the later audit will distinguish ignored blanks from rejected records.
Predict, explain, then test
These three brief checks are self-reviewed, not a scored quiz. Answer before opening the comparison. Coding checks follow the stated task assumptions on unfamiliar inputs.
Locate decoding
Where should loads be called for a two-line JSONL batch?
Compare your answer · self-reviewed
Inside the loop, once for each current line, not on the entire batch.
Choose a format
Is compact JSON with no spaces after colons wrong?
Compare your answer · self-reviewed
No. Whitespace does not change decoded data. A single document per line matters here.
State the assumption
Do these introductory JSONL loops safely handle malformed rows?
Compare your answer · self-reviewed
No. They assume valid rows. The independent audit adds explicit handling and reports rejections.
Choose an exercise to load its prompt.
Loading exercises…
Noted on your route map, with the step you were on. Nothing is lost by parking it — the next review day will bring this idea back, and the flag tells the course where to slow down.
The tutor mounts here when JavaScript is available. The lesson above stays readable without it.