TOON vs YAML: Format Comparison
YAML is popular for configuration files, but is it optimized for LLM prompts? Discover how TOON builds on YAML's readability while adding token efficiency.
Key Similarities & Differences
What They Share
- ✓Both use indentation for nested objects (no braces)
- ✓Human-readable, whitespace-significant syntax
- ✓Support for complex data structures
- ✓More readable than JSON for nested data
Key Differences
YAML Arrays
employees:
- id: 1
name: Alice
role: Engineer
- id: 2
name: Bob
role: Designer
- id: 3
name: Charlie
role: ManagerReadable but verbose with repeated keys
TOON Arrays (Tabular)
employees[3]{id,name,role}:
1,Alice,Engineer
2,Bob,Designer
3,Charlie,ManagerCompact CSV-style format, 50% fewer tokens
When to Choose YAML vs TOON
Choose YAML For:
- • Configuration files (docker-compose, CI/CD)
- • Infrastructure as Code (Kubernetes, Ansible)
- • Human-edited documents
- • Comments needed in files
- • Complex anchors and references
Choose TOON For:
- • LLM prompts and AI applications
- • Token cost optimization
- • Tabular/uniform data structures
- • Better parsing accuracy for AI
- • Data-heavy LLM interactions
Token Efficiency Comparison
| Data Type | YAML Tokens | TOON Tokens | Savings |
|---|---|---|---|
| Nested Object | 45 | 42 | 7% |
| Array of 10 Objects | 182 | 98 | 46% |
| Array of 50 Objects | 890 | 445 | 50% |
| Mixed Structure | 320 | 210 | 34% |
* Token counts measured using GPT-4 tokenizer. Savings increase with dataset size.
Real-World Example: User List
users:
- id: 1001
username: alice_dev
email: alice@example.com
role: admin
active: true
- id: 1002
username: bob_eng
email: bob@example.com
role: developer
active: true
- id: 1003
username: charlie_pm
email: charlie@example.com
role: manager
active: falseusers[3]{id,username,email,role,active}:
1001,alice_dev,alice@example.com,admin,true
1002,bob_eng,bob@example.com,developer,true
1003,charlie_pm,charlie@example.com,manager,falseConfiguration vs Data Representation
YAML Strengths
- ▸Comments Support: Inline documentation for configuration
- ▸Anchors & Aliases: DRY principle for repeated config blocks
- ▸Multi-line Strings: Better for long text blocks
- ▸Ecosystem: Wide tool support (parsers, validators)
TOON Strengths
- ▸Token Efficiency: 30-60% fewer tokens for LLM APIs
- ▸Tabular Data: CSV-like format for uniform arrays
- ▸AI Parsing: Better accuracy for language models
- ▸Cost Savings: Direct reduction in API costs
Migration Guide: YAML to TOON
1Convert YAML to JSON First
Use any YAML-to-JSON converter to get your data in JSON format.
# Using Python
import yaml, json
with open('data.yaml') as f:
data = yaml.safe_load(f)
json_str = json.dumps(data)2Convert JSON to TOON
Use our converter tool to transform JSON into token-efficient TOON format.
3Test with Your LLM
Verify that your language model correctly interprets the TOON format. Most modern LLMs handle TOON natively.
The Verdict
TOON can be thought of as "YAML optimized for LLMs". It retains YAML's readability for nested objects while adding CSV-like efficiency for arrays. If you're working with language models, TOON offers better token efficiency. For configuration files and human editing, YAML remains the better choice.