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.
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.
{
"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.
users[2]{id,name,role,active}:
1,Alice Chen,admin,true
2,Bob Tanaka,editor,trueChoosing 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.
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.
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
- Building Valid JSONL Fine-Tuning Datasets from CSV & JSONFormat valid OpenAI chat, Alpaca, and Gemini fine-tuning .jsonl files from spreadsheets and JSON arrays locally with per-line validation.
- Preparing PDF, Word & Excel as Clean Markdown for RAG & LLMsTurn confidential PDFs, Word DOCX docs, and Excel sheets into structured Markdown for vector chunking and LLM context—100% locally.
- Converting EPUB Ebooks to Markdown for Obsidian & AI StudyUnpack DRM-free EPUB ebooks locally into linked Obsidian Markdown notes or split chapter ZIPs—preserving headings, links, and clean prose.