Input JSON
Output TOON
What is TOON?
Token-Oriented Object Notation (TOON) is a compact, human-readable data format specifically designed to minimize token usage for Large Language Model (LLM) prompts. By combining YAML-like indentation for hierarchy with CSV-style header rows for array of objects, TOON reduces redundancy while keeping the data structure clear for models to parse.
It serves as a drop-in replacement for JSON in LLM contexts, typically offering 30-50% token savings for structured data, which translates to lower costs and more context availability.
Example Conversion
JSON (122 tokens)
{
"users": [
{
"id": 1,
"name": "Alice",
"role": "admin"
},
{
"id": 2,
"name": "Bob",
"role": "user"
},
{
"id": 3,
"name": "Carol",
"role": "user"
}
]
}TOON (58 tokens - 52% savings)
users[3]{id,name,role}:
1,Alice,admin
2,Bob,user
3,Carol,userNotice how TOON eliminates repeated keys by using CSV-style headers, dramatically reducing token count while maintaining full data structure.
Key Features
- Token Efficiency: Drastically reduces token count compared to standard JSON.
- Structure Preservation: Maintains the full schema and type information (unlike pure CSV).
- Human Readable: Easy to read and edit, similar to YAML.
- Lossless Conversion: Convert JSON → TOON → JSON without data loss.
- LLM Friendly: Designed for easy parsing by modern AI models.
Frequently Asked Questions (FAQ)
What is TOON?
TOON (Token-Oriented Object Notation) is a data format designed to be compact and human-readable, minimizing token usage for LLM prompts while maintaining schema structure. It combines YAML-like indentation with CSV-style arrays.
Why should I use TOON instead of JSON for LLMs?
TOON uses significantly fewer tokens than JSON (typically 30-50% less), which reduces API costs and allows you to fit more data into the context window of Large Language Models like GPT-4 or Claude.
Is TOON a lossless format?
Yes, TOON is designed to be a lossless representation of JSON. You can convert JSON to TOON and back to JSON without losing any data structure or values.
How much token savings can I expect?
Savings vary depending on your data structure. TOON is most efficient for arrays of objects (like tables), where it can save up to 50% or more. For deeply nested or irregular data, savings might be lower.
How are token savings calculated?
We use a standard GPT-4 tokenizer (cl100k_base encoding) to count tokens for both the input JSON and the output TOON. The percentage savings represents the reduction in token count, which directly correlates to lower API costs and better context window utilization.
Can I use TOON with any LLM?
Yes, TOON is just text. Most advanced LLMs (GPT-4, Claude 3, etc.) are smart enough to understand and generate TOON format if you provide a few examples or instructions.