JSON is a structured-data format used here in two practical roles: a lightweight persistent store and a constrained format for AI-generated output. A JSON file can retain game data between runs, while a JSON response format can make automated results predictable and easier to use. section 10.8 section 9.5.5
Persist a high-score table
A game can keep its global top five scores in high_scores.json. On reaching the top bank, load existing scores; if the current score qualifies, collect three uppercase alphanumeric initials, update the data, save it, and show the refreshed table. Create the file on first write, but warn and continue if an I/O error occurs. section 10.8
When requesting AI output, name JSON explicitly alongside the constraints that matter. Output control can require a particular layout, filter irrelevant details, and keep generated Python aligned with PEP 8 and snake_case. For example, a requested function can process JSON data by returning only entries whose status is active. section 9.5.5
Useful JSON-oriented requirements include:
- Specify the file location and when it should be created. section 10.8
- Define the data policy, such as retaining only the top five scores while allowing duplicate initials. section 10.8
- State failure behavior, such as warning on I/O errors without stopping gameplay. section 10.8
- Request JSON output directly when a downstream API or program needs a fixed structure. section 9.5.5
Figure 10.16 The JSON structure the game has generated. It is a good lightweight storage method and a data structure we can use later if we want.
Inspect the generated JSON structure as the lightweight data store behind the populated high-score table. section 10.8


































