liveBook · Manning

JSON

As explained in Coding with AI

JSON is a text-based standard format for representing structured data with objects, arrays, and primitive values.

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.
A screenshot of a computer

AI-generated content may be incorrect.

Inspect the generated JSON structure as the lightweight data store behind the populated high-score table. section 10.8

How Coding with AI covers it

How deep it goes
Demonstrates a high-score persistence workflow and JSON output constraints without explaining JSON parsing internals.
Examples
Uses high_scores.json for a top-five table and process_json_data for filtering inactive entries.
What it assumes
Assumes a Python development context while teaching JSON use through concrete prompts and game requirements.
What you can do after
Apply it via Cursor to persist high scores and request JSON-formatted output under explicit constraints.
How it connects
Connects JSON with output control, instruction refinement, Python, PEP 8, snake_case, and APIs.

Also explained in

Compare how 35 books explain JSON →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Coding with AI. The section links point to the parts of the book it draws on.