JSON vs. TOON vs. YAML: LLM BPE Token Benchmarks in 2026
Compare GPT-4o o200k_base BPE token counts across formatted JSON, minified JSON, YAML, CSV, and TOON—plus how TOON cuts prompt array tokens 40%–60%.
On uniform arrays of objects (database rows, search hits, API items), TOON typically reduces GPT-4o o200k_base tokens by 40%–60% compared to formatted JSON and 25%–40% compared to YAML, while staying 100% lossless round-trip back to JSON.
Why JSON burns LLM context budgets on repeated keys
Every time you pass a JSON array of 100 rows into an LLM prompt or RAG context, GPT-4o and Claude repeat every field name, quote pair, colon, and brace 100 times. Even minified JSON eliminates whitespace only, leaving repeated key tokens untouched.
TOON (Token-Oriented Object Notation) keeps YAML-like key nesting for top-level metadata while folding uniform arrays into a single CSV-style schema header such as users[3]{id,name,role,active}:.
| Format | 100-Row User Payload | o200k_base Tokens | Lossless JSON Round-Trip |
|---|---|---|---|
| Formatted JSON | 7.8 KB | ~2,180 tokens | Native |
| Minified JSON | 5.9 KB | ~1,790 tokens | Native |
| YAML 1.2 | 4.6 KB | ~1,340 tokens | Yes (YAML 1.2) |
| TOON (.toon) | 3.1 KB | ~910 tokens (-58%) | Yes (100% lossless) |
When to prune JSON first vs. convert directly to TOON
If your downstream system strictly requires valid JSON (for example, JSON Schema validators or strict API webhooks), use JSON Token Optimizer to strip null properties, empty arrays, and extra whitespace without changing JSON syntax.
When feeding read-only data into an LLM prompt or agent memory, convert JSON, CSV, or YAML straight to TOON and verify exact BPE savings with DataTo LLM Token Counter.
users[3]{id,name,role,active}:
1,Maya Lin,admin,true
2,Jonas Weber,editor,true
3,Sofia Silva,viewer,falseDecoding LLM-generated TOON back into typed JSON
Because TOON headers explicitly declare array length ([3]) and column keys ({id,name,role,active}), strict decoding catches truncated LLM responses immediately before they poison downstream pipelines.
Tools used in this guide
LLM & TOON →Shrink JSON arrays into Token-Oriented Object Notation (TOON) to cut GPT-4o and Claude prompt tokens up to 60%.
LLM Token CounterMeasure exact o200k_base and cl100k_base BPE tokens, context window share, API cost estimates, and TOON savings offline.
JSON Token OptimizerStrip null properties, empty arrays, and whitespace from API JSON payloads to cut LLM token costs while staying 100% valid JSON.
YAML to TOONCompress Kubernetes manifests, OpenAPI specs, and YAML configs into compact TOON for ~42% smaller LLM prompt payloads.
Related formats
Related Comparisons
Frequently asked questions
Do LLMs understand TOON without fine-tuning?
Yes. TOON combines familiar YAML indentation with explicit tabular headers (items[N]{cols}:), so frontier models read and emit it accurately with a single 2-line instruction.
Does TOON beat minified JSON on token count?
Yes. Minifying JSON removes spaces, whereas TOON removes repeated field names and braces—often cutting tokens nearly in half beyond minified JSON.
How does DataTo compute BPE token counts without an API key?
DataTo lazy-loads gpt-tokenizer (o200k_base and cl100k_base) inside local Web Workers so prompts never leave your browser.
Authoritative References
More engineering guides
Inspect Apache Parquet schemas and run full SELECT, JOIN, and GROUP BY SQL queries locally in browser RAM using hyparquet and self-hosted sql.js WASM.
Offline LLM BPE Token Counting & Prompt Cost Optimization GuideCount exact o200k_base and cl100k_base BPE tokens offline, visualize token boundary segments, prune null JSON fields, and cut prompt API costs locally.
OpenAI Batch API JSONL: Unwrapping, Sharding & Validation GuidePrepare OpenAI Batch API JSONL files locally: unwrap nested JSON arrays, deduplicate lines, split shards into ZIP archives, and flatten results to CSV.
XML Attributes to JSON: Lossless @_ Prefix & Round-Trip GuideConvert XML, SVG, RSS, SOAP, and Maven pom.xml to typed JSON with @_ attribute preservation, XXE-safe pure-JS Web Worker parsing, and clean JSON to XML.