Skip to content
LinkedInX

Structured Data for AI: Choosing JSON, YAML, TOON, and TOML

Target audience: People choosing how to pass data to AI or which format to use for configuration
Prerequisites: Experience using prose or tables when working with AI

Structured data makes AI exchanges more dependable

Structured data organizes values according to a defined arrangement of field names, ordering, and nesting. This page explains the differences among JSON, YAML, TOON, and TOML so that you can choose a suitable format for data sent to AI, results returned by AI, and application configuration.

What you’ll learn

  • Explain why the same content can differ in editability, machine processing, and token count across formats
  • Choose among JSON, YAML, TOON, and TOML for data exchange, configuration, and AI input
  • Evaluate compatibility, validation, and data shape instead of choosing a format only for token reduction
  • Compare formats with the model and data you will actually use, then convert them safely

A shipping form is a useful way to recognize structured data. The labels “name” and “address” are field names, the entries are values, and the region and city inside the address form a nested structure. Multiple line items are repeated rows that share the same fields.

In practice, the format corresponds to the form layout, while the data’s meaning corresponds to what is written on it. A correct layout cannot make an incorrect postal code deliverable. In the same way, valid JSON syntax does not prove that required fields and values are meaningful. Add schema or application-level validation where the workflow requires it.

JSON is a language-independent interchange format that represents strings, numbers, booleans, null, objects, and arrays.[1] YAML is a data serialization format designed for human readability, with indentation-based structure and comments.[2] TOML aims to be a minimal configuration format with clear semantics and maps data to tables.[3] These are data formats that define how information is written, not programming languages that instruct a computer to perform operations.

AI input, output, and configuration have different needs

Structured data serves more than one role in an AI system. Separate the boundary where the data is used before choosing a format.

  • Input sent to AI: organize product lists, search results, logs, or evaluation data so that a model can distinguish the fields
  • Output returned by AI: represent summaries, classifications, or extracted fields in a form that another program can reuse
  • AI application configuration: store values such as model settings, processing order, data sources, and evaluation conditions for people and tools to manage

For input, readability and token count can matter. For output, dependable parsing and validation of required fields take priority. For configuration, human editability, support in the existing toolchain, and reviewable diffs matter. A single project can use a different format at each boundary.

Compare the same data in four formats

The following examples encode the same two product records for an AI input. Notice how quotes around field names, delimiters, indentation, and repetition change between formats.

JSON: prioritize machine-to-machine exchange

{
  "products": [
    {"id": 101, "name": "Notebook", "stock": 12},
    {"id": 102, "name": "Pen", "stock": 30}
  ]
}

JSON is the first choice for APIs, database boundaries, tool-call arguments, and other exchanges governed by a machine-readable contract. Libraries are widely available, and the distinction between strings and numbers is explicit. Standard JSON does not support comments, however, and every key and string uses double quotes, which can feel verbose in configuration files that people edit frequently.

YAML: prioritize human-readable configuration and procedures

products:
  - id: 101
    name: Notebook
    stock: 12
  - id: 102
    name: Pen
    stock: 30

YAML often omits braces and quotes and supports comments, making it useful for workflow or deployment configuration managed by people. Indentation defines the structure, so whitespace mistakes and the parser’s type interpretation need attention. When an existing tool requires YAML, follow that contract and use its available validation features.

TOML: prioritize explicit application configuration

[[products]]
id = 101
name = "Notebook"
stock = 12

[[products]]
id = 102
name = "Pen"
stock = 30

TOML uses key = value entries and tables to make configuration fields explicit. Its specification includes date and time types in addition to strings, numbers, and booleans, making it suitable for application and developer-tool configuration.[3] Repeated table declarations grow with a large record set, so TOML is usually not the first candidate for bulk AI input.

TOON: pass uniform records to AI

products[2]{id,name,stock}:
  101,Notebook,12
  102,Pen,30

TOON, or Token-Oriented Object Notation, is a line-oriented, indentation-based representation of the JSON data model. In an array of objects with the same fields, it declares the field names once instead of repeating them on every row, which can shorten AI input.[4]

TOON 4.1 is a Working Draft, and its specification does not position it as a replacement for public APIs or general-purpose storage. JSON can be shorter for irregular or deeply nested data.[4] A practical approach is to keep the data in JSON or another canonical form and treat TOON as a translation layer immediately before AI input.

Token counts depend on more than visible punctuation

A token is a unit into which an AI model divides text and symbols for processing. One character does not always equal one token. A token may represent part of a word, whitespace, punctuation, or a group of symbols. Tokenization rules differ across models and tokenizers, so character count alone cannot determine the exact number of input tokens.[6]

Repeated keys, quotes, braces, commas, spaces, and line breaks are all part of structured input. For a large collection of rows with the same fields, TOON can avoid repeated keys, while CSV can be compact for a simple flat table. For a small or irregular dataset, any savings may disappear once conversion and the instructions needed to explain the format are included.

The published TOON benchmarks show this variation. TOON used fewer tokens than formatted JSON for uniform data, while compact JSON used fewer tokens for nested order data and semi-uniform logs. Absolute counts are tokenizer-specific, so the format name alone does not establish a winner.[5]

For a useful comparison, start from identical content, fields, and encoding. Count each representation with the tokenizer or provider counter for the model you will use. Compare compact JSON as well as formatted JSON, and verify that the model still retrieves the required values correctly.

Choose a format from the use case

Honor the receiving system’s contract first, then consider editing frequency and data shape. Token count becomes a measurement criterion only when more than one compatible option remains.

Use caseFirst candidateWhy it fitsWhat to verify
Exchange with an external APIJSONAligns with the receiving contract and common librariesRequired fields, types, and error responses
Process AI output in codeJSONWorks well with parsing and schema validationOutput constraints and retry behavior after validation failure
Workflow configuration edited by peopleYAMLMakes hierarchy readable and allows commentsIndentation, parser type interpretation, and tool requirements
Application or developer-tool configurationTOMLUses explicit values and tables with a configuration-focused designLibrary support and readability of arrays of tables
Large uniform record set sent to AITOONMay avoid repeated field namesMeasured tokens, model retrieval quality, and reconstruction as JSON
Flat data without nestingCSVKeeps simple rows and columns compactDelimiters, line breaks, types, and missing values
This table scrolls horizontally. Keyboard users can focus the table and use the left and right arrow keys.

Policies and exception rules written in natural language do not need to be forced into a data format. Markdown can hold instructions, while JSON can hold values that code must reuse precisely. Combining formats by responsibility is often easier to maintain than encoding everything the same way.

Convert at boundaries and keep one canonical representation

Case 1: receive order information from AI

When AI extracts an order number, product ID, and quantity for downstream code, request JSON. After parsing, validate rules such as “the order number is a string” and “the quantity is a positive integer,” and do not store invalid data unchanged. Reliable parsing matters more here than saving a handful of tokens.

Case 2: manage AI workflow configuration as a team

YAML is a natural fit when people frequently edit processing order, referenced files, and execution conditions and the workflow tool expects YAML. Choose TOML when an application manages its own settings as explicit keys and tables and the tool treats TOML as its standard. Avoid multiplying formats based on preference alone; prioritize the existing tool contract and the team’s validation method.

Case 3: send a batch of search results to AI

When AI compares hundreds of products or log records, retain the source data in JSON or another canonical representation. Remove fields that the task does not need, convert only the uniform portion to TOON, and compare its token count and retrieval results with compact JSON. Do not adopt TOON if it cannot reconstruct the original JSON-equivalent structure or if answer quality declines.

This operating pattern does not force storage, APIs, and AI input into one format. It defines one meaning-preserving source and converts only where a receiving boundary requires it, which helps balance compatibility and token efficiency.

Validate the choice in five steps

  1. Check the receiving contract: give priority to the format required by the API, tool, or library.
  2. Inspect the data shape: distinguish a uniform table from deep nesting or rows with different fields.
  3. Check how often people edit it: for hand-edited configuration, evaluate comments, diffs, and error-message readability.
  4. Measure the same data: generate every candidate from the same fields, then compare input tokens and retrieval results with the target model’s tokenizer.
  5. Test round-trip conversion and validation: reconstruct the canonical structure and confirm that values, types, record counts, and required fields remain intact.

The choice is ready when its rationale can be stated in terms of use case, receiving system, data shape, or measurement results, and no required value is lost in conversion. When evidence is incomplete, begin with JSON because of its broad interface support, then experiment only where measurement reveals a problem.

Key takeaways

JSON fits machine-to-machine exchange and AI output, YAML and TOML fit human-managed configuration, and TOON fits a translation layer for large, uniform JSON-shaped input. The receiving system’s contract still comes first, and neither TOON nor YAML is guaranteed to use fewer tokens than JSON.

Before settling on a format, measure real data with the real tokenizer and verify parsing, required fields, types, record counts, and round-trip conversion. Token reduction is useful only when meaning and compatibility remain intact.

References

  1. Internet Engineering Task Force, RFC 8259: The JavaScript Object Notation (JSON) Data Interchange Format, December 2017
  2. YAML Language Development Team, YAML Ain’t Markup Language (YAML™) revision 1.2.2, October 1, 2021
  3. TOML, TOML v1.0.0
  4. TOON Format, TOON Specification v4.1, July 26, 2026
  5. TOON Format, Benchmarks
  6. OpenAI, Counting tokens

For the latest releases and updates, check the official website and official documentation.

Quiz