JSON and JSON Lines for AI results

Choose a structure that matches how the next tool loads, processes, and validates records.

Decide whether the result is one document

A JSON array is a natural way to return a small batch as one document. JSON Lines stores a separate valid JSON value on each line. That can make it easier to read a batch record by record, especially when the receiver can process partial results. Both formats need valid JSON values, but their outer shapes are different. Check the downstream importer before asking an assistant to supply either one. 1 2

Preserve record identities

Suppose you ask the assistant to normalize a set of workshop titles. Give it the original workshop ID and require that ID in every result. Define how to represent a title the assistant cannot read and whether it may add new fields. A schema is useful for making those requirements explicit. If the output is line-delimited, check each value against the record schema, and test for duplicate or missing IDs separately. 3

Inspect a small failure before opening the full batch

Use three records, one of which includes embedded quotes and another with a deliberate null field. Parse the result in the intended tool. If a line contains a Markdown fence or an explanatory sentence, a JSON Lines reader can fail on that line. Ask for the data file on its own, then request any interpretation in a separate response. Keep a copy of the original IDs so you can compare the input and output counts by record instead of guessing from file size.

Sources

  1. IETF JSON specification
  2. JSON Lines format
  3. What is JSON Schema?