When to Use TOON
TOON excels in specific scenarios and falls short in others. This guide helps you choose the right format for your use case.TOON’s Sweet Spot
TOON achieves maximum efficiency with uniform arrays of objects—data with the same structure across items:Uniform Structure
All objects have identical fields with primitive values—perfect for tabular format
Token Efficiency
Field names declared once instead of repeated 100 times—massive token savings
LLM Validation
[100] length and {fields} header help models detect truncation and validate structureCSV-like Compactness
Approaches CSV efficiency while remaining fully lossless JSON
Ideal Use Cases
1. Tabular Data for LLMs
When sending structured data to LLMs for analysis, search, or question-answering:Analytics Data
Analytics Data
- LLMs can easily aggregate metrics (sum revenue, count high-bounce days)
[60]length enables “How many days?” queries without counting- Tabular format improves parsing accuracy for numeric operations
Database Query Results
Database Query Results
- Massive token reduction for large result sets
- Preserves type information (timestamps, booleans, nulls)
- Array length helps models understand dataset size
API Responses
API Responses
- Compact representation of API paginated results
- Handles mixed data types (numbers, strings, null)
- Easy for LLMs to answer comparative queries (“Which repo has most stars?“)
2. Mixed-Structure Documents
Data with both nested objects and tabular arrays:Format flexibility: TOON automatically chooses the most efficient representation for each data structure—YAML-style indentation for objects, inline for primitive arrays, tabular for uniform object arrays.
3. LLM-Generated Structured Output
When asking LLMs to generate structured data:Why TOON Helps
Why TOON Helps
- Explicit structure:
[N]lengths and{fields}headers guide model output - Validation: You can detect truncation by checking actual vs declared array length
- Parsing reliability: Tabular format reduces ambiguity compared to freeform JSON
- Token efficiency: Models generate fewer tokens for the same information
4. RAG (Retrieval-Augmented Generation)
For retrieval systems that inject data into prompts:- Token budget optimization: More data fits in context window
- Structure preservation: Full JSON data model support
- LLM comprehension: 76.4% accuracy vs JSON’s 75.0% in benchmarks
When NOT to Use TOON
TOON is not always the best choice. Consider alternatives in these scenarios:1. Deeply Nested or Non-Uniform Structures
Example: Deeply Nested Config
Example: Deeply Nested Config
- JSON compact: 558 tokens
- TOON: 620 tokens (+11.1%)
- JSON pretty: 911 tokens
When This Happens
When This Happens
- Complex configuration files with many nested levels
- Tree structures (file systems, org charts)
- Recursive data structures
- Objects with highly variable field sets
2. Semi-Uniform Arrays
Example: Event Logs with Mixed Structure
Example: Event Logs with Mixed Structure
- JSON compact: 128,529 tokens
- TOON: 154,084 tokens (+19.9%)
3. Pure Tabular Data (CSV Territory)
Context: CSV is smaller than TOON for flat tables. TOON adds ~5-10% overhead for structural features that improve LLM reliability.
Token Comparison: Employee Records
Token Comparison: Employee Records
CSV (47,102 tokens):TOON (49,919 tokens, +6.0%):What TOON adds:
- Array length declaration:
[100] - Key prefix:
employees - Delimiter scoping in header
- Pure tabular data with no nesting
- Token budget is extremely tight
- LLMs already understand your CSV schema
- Need structural validation (
[N]length checking) - Data includes nested objects or multiple arrays
- Want lossless JSON compatibility
4. Latency-Critical Applications
Factors Affecting Latency
Factors Affecting Latency
Time-to-First-Token (TTFT):
- TOON’s lower token count may not always mean faster TTFT
- Model tokenizer efficiency varies by format
- Local models may optimize for common JSON patterns
- Generation speed depends on model implementation
- Some models may parse JSON more efficiently
total = TTFT + (tokens / t/s)- Measure both components for your exact setup
When Latency Matters Most
When Latency Matters Most
- Real-time user-facing applications
- High-throughput batch processing
- Edge deployments with constrained resources
- Applications where milliseconds count (trading, monitoring)
- Profile both TOON and JSON compact in your environment
- Test with representative data samples
- Measure across different model sizes/quantization levels
- Choose the format that performs better for your specific setup
Decision Framework
Use this flowchart to choose the right format:Tabular Eligibility
Tabular eligibility measures what percentage of your data can use TOON’s efficient tabular format:100% Eligible
All arrays are uniform objects with primitive values—maximum token savings
60-80% Eligible
Most arrays are tabular—significant token savings
40-60% Eligible
Mixed structure—modest token savings, evaluate tradeoffs
0-40% Eligible
Minimal tabular data—JSON compact likely more efficient
Calculating Eligibility
Calculating Eligibility
An array is tabular-eligible when:Example:
- All elements are objects
- All objects have identical field sets
- All values are primitives (no nested objects/arrays)
- 5 arrays total
- 3 are tabular-eligible
- Eligibility = 3/5 = 60%
- 100% eligibility: ~60% token reduction vs JSON
- 50% eligibility: ~15% token reduction vs JSON
- 0% eligibility: +10% tokens vs JSON compact (overhead from structure)
Real-World Benchmarks
Token Efficiency by Structure
From TOON’s comprehensive benchmarks:| Dataset | Structure | Eligibility | TOON vs JSON | TOON vs JSON Compact |
|---|---|---|---|---|
| Employee records | Uniform | 100% | −60.7% | −36.9% |
| Time-series analytics | Uniform | 100% | −59.0% | −35.9% |
| GitHub repositories | Uniform | 100% | −42.3% | −23.7% |
| E-commerce orders | Nested | 33% | −33.3% | +5.3% |
| Event logs | Semi-uniform | 50% | −15.0% | +19.9% |
| Nested config | Deep | 0% | −31.9% | +11.1% |
Accuracy Comparison
LLM retrieval accuracy across 209 questions on 4 models:TOON achieves slightly better accuracy (76.4% vs 75.0%) while using 39.9% fewer tokens than JSON.
Quick Reference
Use TOON When...
- Uniform arrays of objects (80%+ tabular eligibility)
- Sending structured data to LLMs
- Token budget is a concern
- Need validation guardrails (
[N]lengths,{fields}headers) - Want lossless JSON compatibility with better efficiency
Use JSON Compact When...
- Deeply nested structures (0-40% tabular eligibility)
- Non-uniform data with variable fields
- Already have JSON pipelines
- Latency benchmarks favor JSON in your environment
Use CSV When...
- Pure flat tables with no nesting
- Token budget is extremely tight
- Don’t need structural validation
- LLMs already understand your CSV schema
Benchmark When...
- Latency is critical
- Tabular eligibility is 40-60% (marginal case)
- Deploying to local/quantized models
- Unsure which format fits your use case
Try It Yourself
Playground
Convert your JSON to TOON and compare token counts
Benchmarks
See detailed comparisons across data structures
Quick Start
Install the library and test with your data
