json2toon.co
Secure
12 min read

TOON vs TONL: A Complete Comparison of Token-Optimized Data Formats

Compare TOON vs TONL for LLMs: key differences, performance benchmarks, and when to use each format to optimize AI API costs.

By JSON to TOON Team

When OpenAI and Anthropic started charging per token, and context windows expanded to hundreds of thousands of tokens, an unexpected problem emerged: JSON is too verbose for AI. The open source community responded with TOON and TONL—the first data formats designed specifically for Large Language Models. Benchmarks show not only 30-60% token reduction but also higher accuracy in model responses. But which one should you choose?

Introduction: The Problem with JSON for LLMs

When OpenAI and Anthropic introduced per-token pricing, and context windows in language models expanded to hundreds of thousands of tokens, an unexpected problem was revealed: JSON, the standard data exchange format on the internet, proved inefficient for AI communication. Every API call generated redundant tokens due to verbose syntax—repeating field names, numerous brackets, quotes, and commas. For companies processing millions of requests per month, this translated into tangible costs.

In response, the open source community created TOON (Token-Oriented Object Notation) and TONL (Token-Optimized Notation Language)—the first data formats designed specifically for Large Language Models. Benchmarks show 30-60% reduction in token usage and higher accuracy in model responses compared to JSON. Learn more about what TOON is and introducing TONL.

TOON and TONL: Two Distinct Approaches

TOON and TONL are not variants of the same format, but two different responses to the problem of JSON inefficiency in the context of LLMs.

TOON (Token-Oriented Object Notation)

TOON is a minimalist serialization format created by Johann Schopplich. It acts as a translation layer between JSON and model input. The TOON philosophy is simple: maximize token savings while maintaining human readability. Read our introduction to TOON and TOON specification guide.

Key Characteristics:

  • Minimalist serialization format
  • Version 2.0 released in November 2025
  • Official specification draft with conformance tests
  • Available in 20+ programming languages
  • Designed for simple conversion workflows

TONL (Token-Optimized Notation Language)

TONL, created by Ersin Koca, is a comprehensive data platform for AI applications. It goes beyond simple serialization, offering a type system, schema validation, JSONPath-like query API, indexing, and streaming for multi-gigabyte files. Learn more in our TONL introduction.

Key Characteristics:

  • Complete data platform, not just serialization
  • Version 2.0 with 10 advanced optimization strategies
  • Can achieve up to 60% additional savings in optimal conditions
  • Focuses on TypeScript/JavaScript with plans for expansion
  • Includes query, modification, and indexing capabilities

Key Philosophical Difference

TOON recommends using JSON in application code and converting to TOON only before sending to LLM. TONL, on the other hand, offers replacement of the entire data stack—from storage through queries to validation.

Token Optimization Mechanisms

The effectiveness of TOON and TONL comes from three fundamental mechanisms:

1. Elimination of Repeating Field Names

JSON repeats field names in every object in an array. For 100 products with 5 attributes each, JSON format writes the same field names 100 times, generating 500 occurrences of names plus all the syntax (brackets, commas, quotes).

TOON and TONL declare field names once in the header, then stream only values, similar to CSV.

Example - JSON (89 tokens):

{
  "users": [
    {"id": 1, "name": "Alice", "role": "admin"},
    {"id": 2, "name": "Bob", "role": "user"},
    {"id": 3, "name": "Carol", "role": "editor"}
  ]
}

TOON (45 tokens, 49% reduction):

users[3]{id,name,role}:
1,Alice,admin
2,Bob,user
3,Carol,editor

TONL (49 tokens, 45% reduction):

#version 1.0
users[3]{id:u32,name:str,role:str}:
  1, Alice, admin
  2, Bob, user
  3, Carol, editor

2. Minimization of Punctuation Characters

Every JSON character—curly braces, square brackets, colons, commas, quotes—typically tokenizes separately. TOON eliminates curly braces completely, uses square brackets only in length declarations, and applies quotes selectively.

TOON's quote rules: a string doesn't require quotes if it's a simple identifier without spaces at the edges. Thanks to this, hello world doesn't need quotes, but "hello, world" (with a comma) does. Unicode and emoji work without quotes.

3. Structural Metadata

Array length declarations [N] inform the model exactly how many elements to expect, reducing errors. Field declarations {field1,field2} act like schemas, helping models validate and generate correct data.

In benchmarks, TOON achieved not only 39.6% fewer tokens than JSON, but also higher accuracy: 73.9% vs 69.7% thanks to these structural "safety barriers."

Advanced TONL 2.0 Strategies

TONL adds an optional type system with 8 basic types (u32, i32, u64, i64, f32, f64, str, bool) and compound types. The format with type hints remains 32% smaller than JSON.

TONL 2.0's 10 optimization strategies:

  • Dictionary encoding (30-50% savings)
  • Delta encoding for sequential data (40-60%)
  • Run-length encoding for repetitions (50-80%)
  • Bit packing for booleans (87.5%)
  • Column reordering based on entropy
  • Numeric quantization (20-40%)
  • Schema inheritance (20-40%)
  • Hierarchical grouping (15-30%)
  • Tokenizer-aware optimization (5-15%)
  • Adaptive optimizer selecting the best strategies

Performance Benchmarks

TOON underwent comprehensive testing with 209 questions testing 11 types of data structures on 4 LLM models (Claude Haiku, Gemini 2.5 Flash, GPT-5 Nano, Grok-4). Tokens counted with GPT-5 o200k_base tokenizer.

Token Reduction by Data Type

Data TypeTOON ReductionTONL Reduction
Uniform employee records (100 rows)60.7%~65%
Time-series analytics (60 rows)59.0%~62%
GitHub repositories (100 rows)42.3%~45%
E-commerce orders with nesting (50 rows)33.1%~38%
Deeply nested configuration (11 rows)Significantly lowerSignificantly lower

TONL Performance Benchmarks

TONL version 2.0.3+ passed 589 tests with 100% success. Performance benchmarks (Node.js 20.x, Apple M1 Pro, 16GB RAM):

  • Parsing/decoding: ~1.2ms (1MB, 10K records)
  • Encoding: ~0.8ms
  • Hash index lookup: ~0.05ms (10M records)
  • Stream processing: ~50MB/s with constant 10MB RAM usage

Practical Savings Example

A developer testing employee analysis reported: JSON used 1,344 tokens with 28.4 seconds, TOON used 589 tokens with 23.5 seconds—56% token reduction and 5 seconds speedup.

Feature Comparison

FeatureTOONTONL
Token reduction30-60%32-60%
Type system✅ (8 basic + compound types)
Schema validation✅ (TSL with 13 constraints)
Query API (JSONPath-like)
Modification API (CRUD)
Indexing (Hash, BTree)
Streaming for large files
Advanced optimizations✅ (10 strategies)
Language support20+ languagesTypeScript/JS (more planned)
Official specification✅ (draft)
Learning curveLowMedium

When to Use Each Format

Use TOON When:

  • You need a simple, lightweight format for basic data conversion
  • You want maximum compatibility across programming languages
  • You're implementing a hybrid approach (JSON in code, TOON for LLM)
  • You need a quick integration with minimal learning curve
  • You're working with straightforward tabular data
  • You want to keep your data stack simple

Use TONL When:

  • You need advanced features like querying, indexing, or schema validation
  • You're working with large datasets that require streaming
  • You want to leverage advanced optimization strategies
  • You're building a TypeScript/JavaScript application
  • You need to replace your entire data stack, not just serialization
  • You're building complex AI applications with data manipulation needs
  • You need fuzzy matching, temporal queries, or aggregation capabilities

Practical Use Cases

Optimal Scenarios for Both Formats

  • Product catalogs sent to AI for recommendations
  • Customer data in personalization systems
  • Analytics and reports processed by LLM
  • Database query results (tables: users, transactions, logs)
  • Time-series data (metrics, monitoring)
  • Training data for few-shot learning

Example: E-commerce Product Catalog

An e-commerce system sends a list of 500 products with 8 attributes each to GPT-4 for AI-powered search. In JSON this is ~12,000 tokens. In TOON it's ~5,000 tokens. In TONL with optimizations, it could be ~4,500 tokens. At $0.03 per 1K input tokens and 1M calls per month: savings of $210-225/month from a single endpoint.

Integration with AI Systems

  • RAG (Retrieval-Augmented Generation): Efficient encoding of retrieved documents
  • AI Agents: Exchange of structured data between agents
  • Model Context Protocol: Optimal format for MCP messages
  • Structured prompting: Reducing costs of data-heavy prompts

Implementation Recommendations

Hybrid Approach (Recommended)

  1. Keep JSON for APIs, databases, and application code
  2. Convert to TOON/TONL only before sending to LLM
  3. Reversible transformation—no loss of interoperability

Example Savings at Scale

For 100 million tokens per month with 40% reduction at $0.03 per 1K tokens: savings of $1,200/month.

Limitations and Context

Where Formats Work Best

Optimal data types:

  • Uniform arrays of objects (all objects have the same fields)
  • Tabular data (similar to CSV)
  • Flat or lightly nested structures
  • Primitive values (strings, numbers, booleans)

Less Efficient Scenarios

Problematic cases:

  • Deeply nested structures (many levels)
  • Non-uniform data (different field sets in objects)
  • Complex configurations (nested config objects)
  • Very small payloads (header overhead)

As one developer warns: "As the data becomes more hierarchical, TOON loses its advantage" and "For deeply nested, compact JSON often uses fewer tokens."

Comparison with Alternatives

  • CSV: For simple flat tables, CSV is 5-10% more compact than TOON, but loses flexibility (no nesting, types, metadata).
  • Compact JSON: For deeply nested structures, minified JSON may be more efficient than TOON/TONL.

Recommendation: Test your specific use cases. Efficiency strongly depends on data structure.

Conclusion

TOON and TONL represent a new category of data formats designed specifically for communication with Large Language Models. They achieve 30-60% token reduction compared to JSON for tabular and structured data, translating into tangible API cost savings.

Key Takeaways

  • TOON is a minimalist serialization format—good choice for simple integration
  • TONL is a comprehensive platform—choose when you need queries, validation, streaming
  • Best results for uniform arrays of objects
  • Hybrid implementation (JSON in code, TOON/TONL for LLM) minimizes risk
  • Available libraries in 20+ programming languages (TOON) or TypeScript/JavaScript (TONL)
  • Benchmarks show not only cost reduction but also higher model accuracy. See our API cost optimization guide for practical tips.

Who Should Use These Formats?

  • E-commerce applications with AI-powered features (search, recommendations, analytics)
  • Systems processing large amounts of structured data through LLM
  • Companies with high LLM API costs (millions of requests/month)
  • Projects with data-heavy prompts (RAG, agents, MCP)

Testing Recommendations

  1. Start with a small test—one endpoint, measure savings
  2. Use your model's actual tokenizer for measurement
  3. Measure not only tokens but also accuracy and response time
  4. Calculate actual ROI in dollars
  5. If results are positive: scale gradually

The open source community has created solid infrastructure around these formats with official specifications, tests, and production implementations. While there's a lack of academic validation in the form of peer-reviewed papers, the formats are actively used and developed with clear benefits for appropriate use cases.

Resources and Further Reading

TOONTONLComparisonToken OptimizationLLMData Format