Guides

TOON vs JSON: Cutting LLM Prompt Token Cost by 30–60%

See how Token-Oriented Object Notation (TOON) eliminates repeated JSON keys in uniform arrays to cut GPT-5, Claude 4, and Gemini 2.5 prompt costs.

3 min read

Quick Answer: Token-Oriented Object Notation (TOON) cuts LLM input token usage by 30% to 60% on uniform JSON object arrays by declaring property keys once in a compact header (`users[N]{id,name}:`) and using YAML-style indentation for nesting, while round-tripping losslessly back to typed JSON in browser RAM.

Why standard JSON wastes half your context window

JSON was designed for JavaScript parsing rather than LLM byte-pair tokenization. Whenever you embed a 50-row database query or API response inside a prompt, JSON repeats every quoted key name, colon, brace, and comma on all 50 items.

In o200k_base and Claude tokenizers, structural punctuation and repeated identifiers frequently consume 40% to 60% of total input tokens before the model even reads your actual values.

  • Repeated property keys add dead token weight on uniform arrays.
  • Double quotes and curly braces split into extra separator tokens.
  • Long JSON arrays push RAG prompts closer to context window caps.
json
{
  "users": [
    { "id": 1, "name": "Alice Chen", "role": "admin", "active": true },
    { "id": 2, "name": "Bob Tanaka", "role": "editor", "active": true }
  ]
}

How TOON declares keys once with YAML + CSV ergonomics

TOON (Token-Oriented Object Notation) uses clean YAML-style indentation for nested objects and switches uniform arrays into a single declared header (`users[N]{id,name,role,active}:`) followed by comma-, tab-, or pipe-delimited rows.

Unlike bare CSV, TOON preserves nested hierarchies, explicit element counts (`[N]`), and strict schema fidelity so models still parse fields reliably while shrinking token usage by roughly half.

toon
users[2]{id,name,role,active}:
  1,Alice Chen,admin,true
  2,Bob Tanaka,editor,true

Convert JSON to TOON with live token savings

Choosing delimiters and measuring real savings locally

Comma delimiters are easiest for humans to scan, while switching TOON's delimiter to tab (`\t`) or pipe (`|`) can shave another 3%–8% of tokens when strings contain spaces or punctuation.

Before deploying a prompt pipeline change, test your exact payload with TxtTo's live token bar comparing GPT-5 (o200k), Claude 4, and Gemini 2.5 locally—without pasting proprietary customer JSON into external tokenizers.

Compare GPT-5, Claude 4 & Gemini 2.5 token counts

Lossless round-tripping back from TOON to JSON

When an AI workflow or documentation store saves TOON payloads, `@toon-format/toon` decodes them deterministically back into typed JSON arrays, numbers, booleans, and nested objects.

Avoid using TOON for deeply heterogeneous trees where every row has completely different keys—standard minified JSON or JSONL remains optimal there.

Decode TOON back to JSON locally

References

Frequently asked questions

Does TOON reduce LLM accuracy compared to JSON?

No. Explicit length markers like [4] and declared column headers give LLMs clear row boundaries while removing repetitive syntax noise.

When does TOON save the most tokens?

Uniform arrays of 3+ objects with 4 or more fields routinely drop 35%–60% in token count compared to formatted JSON.

Is TOON lossless when converting back to JSON?

Yes. Strings, numbers, booleans, nulls, and nested objects round-trip back to valid JSON cleanly.

Related formats

Related Comparisons

Related Guides