Toon
π Token-Oriented Object Notation (TOON) β Compact, human-readable, schema-aware JSON for LLM prompts. Spec, benchmarks, TypeScript SDK.
Install / Use
/learn @toon-format/ToonREADME

Token-Oriented Object Notation (TOON)
Token-Oriented Object Notation is a compact, human-readable encoding of the JSON data model that minimizes tokens and makes structure easy for models to follow. It's intended for LLM input as a drop-in, lossless representation of your existing JSON.
TOON combines YAML's indentation-based structure for nested objects with a CSV-style tabular layout for uniform arrays. TOON's sweet spot is uniform arrays of objects (multiple fields per row, same structure across items), achieving CSV-like compactness while adding explicit structure that helps LLMs parse and validate data reliably. For deeply nested or non-uniform data, JSON may be more efficient.
The similarity to CSV is intentional: CSV is simple and ubiquitous, and TOON aims to keep that familiarity while remaining a lossless, drop-in representation of JSON for Large Language Models.
Think of it as a translation layer: use JSON programmatically, and encode it as TOON for LLM input.
[!TIP] The TOON format is stable, but also an idea in progress. Nothing's set in stone β help shape where it goes by contributing to the spec or sharing feedback.
Table of Contents
- Why TOON?
- Key Features
- When Not to Use TOON
- Benchmarks
- Installation & Quick Start
- Playgrounds
- Editor Support
- CLI
- Format Overview
- Using TOON with LLMs
- Documentation
- Other Implementations
- π Full Specification
Why TOON?
AI is becoming cheaper and more accessible, but larger context windows allow for larger data inputs as well. LLM tokens still cost money β and standard JSON is verbose and token-expensive:
{
"context": {
"task": "Our favorite hikes together",
"location": "Boulder",
"season": "spring_2025"
},
"friends": ["ana", "luis", "sam"],
"hikes": [
{
"id": 1,
"name": "Blue Lake Trail",
"distanceKm": 7.5,
"elevationGain": 320,
"companion": "ana",
"wasSunny": true
},
{
"id": 2,
"name": "Ridge Overlook",
"distanceKm": 9.2,
"elevationGain": 540,
"companion": "luis",
"wasSunny": false
},
{
"id": 3,
"name": "Wildflower Loop",
"distanceKm": 5.1,
"elevationGain": 180,
"companion": "sam",
"wasSunny": true
}
]
}
<details>
<summary>YAML already conveys the same information with <strong>fewer tokens</strong>.</summary>
context:
task: Our favorite hikes together
location: Boulder
season: spring_2025
friends:
- ana
- luis
- sam
hikes:
- id: 1
name: Blue Lake Trail
distanceKm: 7.5
elevationGain: 320
companion: ana
wasSunny: true
- id: 2
name: Ridge Overlook
distanceKm: 9.2
elevationGain: 540
companion: luis
wasSunny: false
- id: 3
name: Wildflower Loop
distanceKm: 5.1
elevationGain: 180
companion: sam
wasSunny: true
</details>
TOON conveys the same information with even fewer tokens β combining YAML-like indentation with CSV-style tabular arrays:
context:
task: Our favorite hikes together
location: Boulder
season: spring_2025
friends[3]: ana,luis,sam
hikes[3]{id,name,distanceKm,elevationGain,companion,wasSunny}:
1,Blue Lake Trail,7.5,320,ana,true
2,Ridge Overlook,9.2,540,luis,false
3,Wildflower Loop,5.1,180,sam,true
Key Features
- π Token-Efficient & Accurate: TOON reaches 74% accuracy (vs JSON's 70%) while using ~40% fewer tokens in mixed-structure benchmarks across 4 models.
- π JSON Data Model: Encodes the same objects, arrays, and primitives as JSON with deterministic, lossless round-trips.
- π€οΈ LLM-Friendly Guardrails: Explicit [N] lengths and {fields} headers give models a clear schema to follow, improving parsing reliability.
- π Minimal Syntax: Uses indentation instead of braces and minimizes quoting, giving YAML-like readability with CSV-style compactness.
- π§Ί Tabular Arrays: Uniform arrays of objects collapse into tables that declare fields once and stream row values line by line.
- π Multi-Language Ecosystem: Spec-driven implementations in TypeScript, Python, Go, Rust, .NET, and other languages.
Media Type & File Extension
By convention, TOON files use the .toon extension and the provisional media type text/toon for HTTP and content-typeβaware contexts. TOON documents are always UTF-8 encoded; the charset=utf-8 parameter may be specified but defaults to UTF-8 when omitted. See SPEC.md Β§18.2 for normative details.
When Not to Use TOON
TOON excels with uniform arrays of objects, but there are cases where other formats are better:
- Deeply nested or non-uniform structures (tabular eligibility β 0%): JSON-compact often uses fewer tokens. Example: complex configuration objects with many nested levels.
- Semi-uniform arrays (~40β60% tabular eligibility): Token savings diminish. Prefer JSON if your pipelines already rely on it.
- Pure tabular data: CSV is smaller than TOON for flat tables. TOON adds minimal overhead (~5-10%) to provide structure (array length declarations, field headers, delimiter scoping) that improves LLM reliability.
- Latency-critical applications: If end-to-end response time is your top priority, benchmark on your exact setup. Some deployments (especially local/quantized models like Ollama) may process compact JSON faster despite TOON's lower token count. Measure TTFT, tokens/sec, and total time for both formats and use whichever is faster.
See benchmarks for concrete comparisons across different data structures.
Benchmarks
Benchmarks are organized into two tracks to ensure fair comparisons:
- Mixed-Structure Track: Datasets with nested or semi-uniform structures (TOON vs JSON, YAML, XML). CSV excluded as it cannot properly represent these structures.
- Flat-Only Track: Datasets with flat tabular structures where CSV is applicable (CSV vs TOON vs JSON, YAML, XML).
Retrieval Accuracy
<!-- automd:file src="./benchmarks/results/retrieval-accuracy.md" -->Benchmarks test LLM comprehension across different input formats using 209 data retrieval questions on 4 models.
<details> <summary><strong>Show Dataset Catalog</strong></summary>Dataset Catalog
| Dataset | Rows | Structure | CSV Support | Eligibility | | ------- | ---- | --------- | ----------- | ----------- | | Uniform employee records | 100 | uniform | β | 100% | | E-commerce orders with nested structures | 50 | nested | β | 33% | | Time-series analytics data | 60 | uniform | β | 100% | | Top 100 GitHub repositories | 100 | uniform | β | 100% | | Semi-uniform event logs | 75 | semi-uniform | β | 50% | | Deeply nested configuration | 11 | deep | β | 0% | | Valid complete dataset (control) | 20 | uniform | β | 100% | | Array truncated: 3 rows removed from end | 17 | uniform | β | 100% | | Extra rows added beyond declared length | 23 | uniform | β | 100% | | Inconsistent field count (missing salary in row 10) | 20 | uniform | β | 100% | | Missing required fields (no email in multiple rows) | 20 | uniform | β | 100% |
Structure classes:
- uniform: All objects have identical fields with primitive values
- semi-uniform: Mix of uniform and non-uniform structures
- nested: Objects with nested structures (nested objects or arrays)
- deep: Highly nested with minimal tabular eligibility
CSV Support: β (supported), β (not supported β would require lossy flattening)
Eligibility: Percentage of arrays that qualify for TOON's tabular format (uniform objects with primitive values)
</details>Efficiency Ranking (Accuracy per 1K Tokens)
Each format ranked by efficiency (accuracy percentage per 1,000 tokens):
TOON ββββββββββββββββββββ 27.7 acc%/1K tok β 76.4% acc β 2,759 tokens
JSON compact ββββββββββββββββββββ 23.7 acc%/1K tok β 73.7% acc β 3,104 tokens
YAML ββββββββββββββββββββ 19.9 acc%/1K tok β 74.5% acc β 3,749 tokens
JSON ββββββββββββββββββββ 16.4 acc%/1K tok β 75.0% acc β 4,587 tokens
XML ββββββββββββββββββββ 13.8 acc%/1K tok β 72.1% acc β 5,221 tokens
Efficiency score = (Accuracy % Γ· Tokens) Γ 1,000. Higher is better.
[!TIP] TOON achieves 76.4% accuracy (vs JSON's 75.0%) while using 39.9% fewer tokens.
Note on CSV: Excluded from ranking as it only supports 109 of 209 questions (flat tabular data only). While CSV is highly token-efficient for simple tabular data, it cannot represent nested structures that other formats handle.
Per-Model Accuracy
Accuracy across 4 LLMs on 209 data retrieval questions:
claude-haiku-4-5-20251001
β TOON ββββββββββββββββββββ 59.8% (125/209)
JSON ββββββββββββββββββββ 57.4% (120/209)
YAML ββββββββββββββββββββ 56.0% (117/209)
XML βββββββββ
