JSON, YAML, and TOON all describe the same underlying data — objects, arrays, strings, numbers, booleans, and null — but each notation optimizes for something different. JSON optimizes for universal interoperability. YAML optimizes for human editing. TOON optimizes for token efficiency when that same data has to sit inside an LLM prompt. Picking the wrong one costs you readability, tooling support, or money on every API call — so it's worth understanding exactly how each one differs before you choose.
🧩 Why Format Choice Matters
Three things tend to decide which format is right for a given job: how easy the data is for a human to read and edit by hand, how well existing tools and libraries in your stack already parse it, and — increasingly — how many tokens it costs when that data has to be pasted into an LLM's context window. A config file that a developer edits directly should prioritize readability and comments. An API response that flows between services should prioritize universal support. A batch of records stuffed into a prompt for an AI agent should prioritize token cost, since every token in the prompt adds to latency and API spend.
🔍 The Same Data, Three Ways
Here's one small product catalog, converted to all three formats using this site's own converters. Notice how the structure stays identical — only the notation changes.
JSON
{
"products": [
{ "id": 101, "name": "Wireless Mouse", "price": 24.99, "inStock": true },
{ "id": 102, "name": "USB-C Hub", "price": 39.5, "inStock": true },
{ "id": 103, "name": "Laptop Stand", "price": 45, "inStock": false }
]
}
Every object repeats id, name, price, and
inStock — that repetition is what makes JSON verbose for arrays of records,
even though it's what makes JSON so easy for every parser on the planet to consume
without ambiguity.
YAML
products:
-
id: 101
name: Wireless Mouse
price: 24.99
inStock: true
-
id: 102
name: USB-C Hub
price: 39.5
inStock: true
-
id: 103
name: Laptop Stand
price: 45
inStock: false
This is the exact output of this site's JSON to YAML converter
for the dataset above. Notice the dash for each array item sits alone on its own line,
with the object's keys indented underneath it on the following lines, rather than the
more compact - id: 101 inline style you may have seen in hand-written YAML
elsewhere — both are valid YAML, but this converter's array-of-objects output always
puts the dash on its own line. YAML still drops the quotes JSON requires around string
keys and values, and — unlike JSON — it lets you add # comments anywhere in
the file, which is a big part of why it's the default for hand-edited config formats like
Docker Compose, Kubernetes manifests, GitHub Actions workflows, and Ansible playbooks.
TOON
products[3]{id,name,price,inStock}:
101,Wireless Mouse,24.99,true
102,USB-C Hub,39.5,true
103,Laptop Stand,45,false
This is what this site's JSON to TOON converter
produces for the same input. Because all three products share the exact same set of keys
in the same order, TOON recognizes this as a uniform array of objects and switches to its
tabular form: products[3] declares there are 3 rows, {id,name,price,inStock}
declares the field names once, and every line after that is pure comma-separated data with
no field names repeated at all. That's the entire mechanism behind TOON's token savings —
it's the same information as the JSON above, just without paying the "repeat every key,
every row" tax.
📋 Comparison Table
| Format | Best For | Readability | Comments Support | Token Efficiency for LLMs | Tooling Support |
|---|---|---|---|---|---|
| JSON | APIs, data interchange, storage | Moderate — quoted keys and strict syntax add noise | No | Low for arrays of objects — repeats keys per item | Universal — every language and platform |
| YAML | Hand-edited config files | High — minimal punctuation, indentation-based | Yes, with # |
Low — still repeats keys per array item | Broad — most languages, common in DevOps tooling |
| TOON | LLM prompts, RAG context, agent tool I/O | High for uniform data — tabular rows scan easily | No | High — published benchmarks report ~42.6% fewer tokens than JSON | Emerging — spec plus a growing set of converters |
On that same published benchmark, TOON also reported comparable-or-better LLM retrieval accuracy than JSON (72.2% vs. JSON's 71.4%) despite using fewer tokens — so the token savings didn't come at the cost of the model actually finding the right data. None of these three formats is universally "better." Each one is the right tool for a specific job, and the sections below walk through exactly which job that is.
🌐 When to Use JSON
Reach for JSON whenever the data needs to move between systems, languages, or teams without any ambiguity about how to parse it:
- REST and GraphQL APIs: Nearly every HTTP client, server framework, and API gateway expects JSON by default
- Persisted application state: Browser localStorage, NoSQL documents, and JSON columns in relational databases
- Cross-language data exchange: When a Python service, a JavaScript frontend, and a Java backend all need to agree on one wire format
- Anywhere strictness helps: JSON's lack of comments and trailing commas means there's exactly one valid way to write a given value, which reduces parsing ambiguity
⚙️ When to Use YAML
Reach for YAML whenever a human is going to read or edit the file directly, and being able to explain a setting with a comment matters:
- Docker Compose files: Defining multi-container application services, networks, and volumes
- Kubernetes manifests: Deployments, services, and config maps that ops teams read and tweak by hand
- CI/CD pipelines: GitHub Actions workflows and similar pipeline definitions that benefit from inline comments explaining each step
- Configuration management: Ansible playbooks and other tools where non-developers may need to read the file
🤖 When to Use TOON
Reach for TOON specifically when structured data is headed into an LLM's context window, and the cost or size of that context matters:
- RAG pipelines: Stuffing retrieved documents or database rows into a prompt as context
- AI agent tool calls: Passing structured tool outputs and API responses back to the model
- Search results: Sending lists of ranked results to an LLM for summarization or reasoning
- Large, uniform datasets: The token savings scale with the number of rows in a uniform array, so bigger tabular datasets benefit the most
🌟 Pro Tip
These formats aren't mutually exclusive across a single system. It's common to store data as JSON, let developers configure services with YAML, and convert JSON to TOON only at the moment it's serialized into an LLM prompt — keeping JSON as the source of truth throughout.
❓ Frequently Asked Questions
Is TOON meant to replace JSON or YAML?
No. TOON is purpose-built for one job: reducing token usage when structured data is sent to an LLM inside a prompt. JSON remains the right choice for APIs and general data interchange, and YAML remains the right choice for human-edited configuration files. TOON converts losslessly to and from JSON, so you can keep JSON as your source of truth and generate TOON only for the prompt itself.
Can YAML or TOON represent anything JSON can't?
No. All three formats represent the same underlying data model of objects, arrays, strings, numbers, booleans, and null. YAML and TOON are just different textual notations for that same data; converting between them and JSON does not lose information for standard data structures.
Why does JSON use more tokens than TOON for the same data?
JSON repeats every field name (key) for every object in an array. A list of 100 records repeats "id", "name", and every other key 100 times. TOON declares the field names once in a header row for a uniform array of objects, then lists each row as comma-separated values with no repeated keys, which is what drives its token savings.
Does YAML support comments, and does JSON?
YAML supports comments using #, which is a major reason it's favored
for hand-edited configuration files like Docker Compose, Kubernetes manifests,
GitHub Actions workflows, and Ansible playbooks. Standard JSON has no comment
syntax at all.
Which format should I use for an AI agent's tool call output?
If the tool output is a uniform array of objects (search results, database rows, API records) and it's being placed inside an LLM prompt or context window, TOON is the best fit because it avoids repeating keys per row. If the same output is being returned over an API to another program, stick with JSON since that's what virtually every HTTP client and library expects.
🚀 Try It Yourself
Paste your own JSON into these converters to see it in each format instantly:
- JSON Formatter and Prettifier — clean up and validate raw JSON
- JSON to YAML Converter — convert JSON into readable, config-friendly YAML
- JSON to TOON Converter — convert JSON into TOON's token-efficient tabular format
- Full Documentation — the complete TOON syntax reference