T

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: Manager

Readable but verbose with repeated keys

TOON Arrays (Tabular)

employees[3]{id,name,role}:
  1,Alice,Engineer
  2,Bob,Designer
  3,Charlie,Manager

Compact 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 TypeYAML TokensTOON TokensSavings
Nested Object45427%
Array of 10 Objects1829846%
Array of 50 Objects89044550%
Mixed Structure32021034%

* Token counts measured using GPT-4 tokenizer. Savings increase with dataset size.

Real-World Example: User List

YAML Format(182 tokens)
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: false
TOON Format(98 tokens - 46% savings)
users[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,false

Configuration 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.

Try TOON Format

Convert your YAML or JSON data to TOON and see the difference.

Use the Converter