In the age of large language models (LLMs) every token counts—both for cost and for effective use of the context window. If you pass structured data into an LLM, you’ve probably defaulted to JSON or YAML. TOON (Token-Oriented Object Notation) is a compact, LLM-focused data serialization format built to reduce token overhead while keeping data readable and structured.
What is TOON?
TOON is a serialization format tuned for LLM-driven workflows. Where JSON was designed for machine-to-machine interchange, TOON optimizes for compactness when text is being consumed by an LLM API. Instead of relying on abundant punctuation (curly braces, commas, quotes), TOON uses minimal syntax and indentation to express structure, aiming to lower token counts without losing clarity.
How TOON Works: Key Design Elements
1. Minimal syntax
TOON removes punctuation overhead where possible:
- No curly braces
{}for objects - No repeated array brackets; arrays can use length markers
- Quotes only when strictly needed (strings containing special characters)
- Simple
key: valuepairs
Example
{
"name": "Alice",
"age": 30,
"city": "New York"
}
TOON equivalent:
name: Alice
age: 30
city: New York
2. Indentation for hierarchy
TOON uses indentation for nested structures (similar to YAML). This cuts punctuation while keeping structure unambiguous to LLMs.
user:
name: Alice
profile:
age: 30
city: New York
3. Tabular array optimization
When your data is tabular—many records with the same fields—TOON declares fields once and then lists rows. That saves repetition and tokens.
JSON
[
{ "id": 1, "name": "Alice", "age": 30 },
{ "id": 2, "name": "Bob", "age": 25 },
{ "id": 3, "name": "Charlie", "age": 35 }
]
TOON
[3,]{id,name,age}:
1,Alice,30
2,Bob,25
3,Charlie,35
The header [3,] signals length, and the field list {id,name,age} declares columns once—rows follow as comma-separated values.
Why It Matters: Real-World Impact
TOON can deliver measurable benefits for systems that call LLMs with structured data:
- Token savings — lower API costs by reducing overhead.
- Faster throughput — smaller payloads are quicker to transfer and parse.
- More context space — reclaim your context window for content and reasoning rather than punctuation.
- Readable for LLMs — compact but structured formats are easy for models to interpret.
Tabular data (logs, inventories, analytics rows) benefits most—the more uniform the records, the greater the savings.
Ideal Use Cases for TOON
TOON is especially useful when you have:
- Collections of uniformly structured records (orders, user lists, telemetry rows)
- Workflows that make frequent LLM calls with structured input
- Constraints on token budget or context-window size
- RAG (retrieval-augmented generation), analytics pipelines, or table ingestion for chatbots
When JSON might be better:
- Highly irregular or extremely deep nested structures
- When human editability is more important than token efficiency
- Occasional, low-volume LLM calls where savings don’t matter
Multi-Language Support & Ecosystem
TOON implementations and converters are available or developing across common stacks, making integration easier:
- JavaScript / TypeScript
- Python (CLI / library for JSON ↔ TOON)
- Go, .NET / C#, PHP
Choose a converter in your stack to serialize to TOON before sending prompts to your LLM.
Getting Started: Sample Workflow (Python)
Minimal example showing how TOON fits into a Python LLM pipeline:
import toon
import json
# Sample data: list of employees
employees = [
{"id": 1, "name": "Alice", "department": "Engineering", "salary": 120000},
{"id": 2, "name": "Bob", "department": "Marketing", "salary": 95000},
{"id": 3, "name": "Charlie","department": "Engineering","salary": 110000}
]
# Convert to TOON
toon_data = toon.encode(employees)
# Use as LLM prompt
prompt = f"Analyze this employee data:\n{toon_data}\n\nWhat is the average salary by department?"
# pass prompt to your LLM API
Note: Replace toon.encode with the actual library/command from your TOON implementation.
Performance Considerations & Metrics
Benchmarks and practical observations:
- Token reductions of roughly 30–60% observed on structured/tabular data in many tests.
- Smaller prompts free more of the context window for model reasoning and facts.
- TOON is plain text; any LLM that accepts structured text can parse it.
- If your dataset is deeply irregular, TOON’s benefits shrink and JSON or other formats may be more convenient.
Frequently Asked Questions (FAQ)
- Is TOON compatible with all LLMs?
- Yes. TOON is plain text; models from OpenAI, Anthropic, and other providers can consume it as part of prompts.
- How much money can I save by using TOON?
- Savings depend on token volume and prompt complexity. For frequent structured prompts, a 30–40% reduction in data size can yield meaningful cost savings.
- Can LLMs emit TOON-formatted output?
- Technically yes, but most downstream tools expect JSON. It’s common to send TOON in and receive JSON back, or to post-process LLM output into TOON if desired.
- Will TOON affect model accuracy?
- Benchmarks suggest TOON does not degrade accuracy and may improve clarity by removing repetitive punctuation; models often find the compact format easier to process.
Conclusion
As LLM-driven systems scale, optimizing token usage becomes essential. TOON offers a practical, compact alternative to JSON for structured inputs—especially tabular data and frequent LLM calls. It helps reduce token cost, frees up context window space, and keeps your prompts concise.
