Engineering Guides5 min readUpdated: 2026-11-24

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%.

Quick Answer

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}:.

Format100-Row User Payloado200k_base TokensLossless JSON Round-Trip
Formatted JSON7.8 KB~2,180 tokensNative
Minified JSON5.9 KB~1,790 tokensNative
YAML 1.24.6 KB~1,340 tokensYes (YAML 1.2)
TOON (.toon)3.1 KB~910 tokens (-58%)Yes (100% lossless)

Convert JSON to TOON locally (-58%) →

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,false

Measure exact BPE tokens offline →

Decoding 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.

Decode TOON back to typed JSON →

Tools used in this guide

LLM & TOON →

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