Choose an array for repeated items

Use the opposite Shift key for paired punctuation. · 156 words

Structured output works best when the prompt names the source, item shape, and exact top-level JSON type. A museum has three tour records: Museum Walk, 10:00, 12 seats; Painting Lab, 13:00, 8 seats; and City Sketching, 15:00, 20 seats. Prompt: "Return every tour from the source as a top-level array. Each item must have name (string), time (string), and seats (integer). Keep source order and add no commentary." An array fits because the tours are repeated records, while the schema tells the model how to copy each one.

Worked output: [{"name":"Museum Walk","time":"10:00","seats":12},{"name":"Painting Lab","time":"13:00","seats":8},{"name":"City Sketching","time":"15:00","seats":20}]. Check it by parsing the JSON, confirming Array.isArray(result) is true, and testing that result.length is 3. Also test each item's keys and value types. These checks catch wrapping the list in an object, dropping a tour, or changing 12 to "12". If order matters, compare the names with the source list in sequence. A valid array can still have the wrong order.

Check your recall

What top-level JSON shape should a prompt request for the three museum tours, and what checks can confirm that shape?

Check your answer

Request a top-level array. Parse the result, confirm Array.isArray(result) is true, check that its length is 3, and verify each item's keys, value types, and order.

Sources and credits

Original KeyTouch lesson. Background reading · JSON Schema · Understanding JSON Schema.