Skip to main content
Back to Blog

Introducing TOON: The Token-Oriented Object Notation

TOON is a token-efficient format that keeps your data structure but uses fewer characters and fewer LLM tokens than JSON.

Kashyap Thakar
6 min
TOONAILLMOptimizationData Format
Introducing TOON: The Token-Oriented Object Notation

In the age of Large Language Models (LLMs), every token counts. JSON has been the de-facto standard for data exchange for decades, but it wasn't built for the token-constrained world of AI. Enter TOON (Token-Oriented Object Notation) a new, schema-aware data serialization format specifically designed to optimize structured data exchange with LLMs.

Why TOON?

JSON is verbose. Braces, quotes, and commas add significant overhead when you are paying per token or limited by context windows. TOON adopts a minimalistic, indentation-based syntax that removes this clutter, which cuts token counts for uniform datasets. In our measurements, TOON used roughly 25-34% fewer tokens than minified JSON and 54-61% fewer than pretty-printed JSON on flat, uniform records.

TOON vs JSON: A Comparison

Let's look at a simple example. Here is a list of users in JSON:


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

How TOON Syntax Works

TOON is designed to be as minimal as possible while retaining structure. It supports three delimiter modes to fit your workflow:

1. Pipe Mode (Default)

Ideal for clean, visually separated data.

  • Arrays: [count]{key1|key2}| followed by rows.
  • Objects: key|value.

2. Comma Mode (CSV-style)

Great for compactness and familiarity with CSV tools.

  • Arrays: [count]{key1,key2}, followed by rows.
  • Objects: key,value.

3. Tab/Standard Mode (YAML-like)

Best for readability, resembling YAML but more compact.

  • Arrays: [count]{key1,key2}: followed by rows.
  • Objects: key: value.

Comparative Example

Original JSON:


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

TOON (Pipe Mode):


[2]{id|name|role}|
  1|Alice|admin
  2|Bob|user
                    

TOON (Tab/Standard Mode):


[2]{id,name,role}:
  1,Alice,admin
  2,Bob,user
                    

Notice the difference? TOON leverages a tabular structure for arrays of objects, eliminating repetitive keys and punctuation. This not only saves tokens but also makes it easier for LLMs to parse and understand the structure.

Key Benefits

  • Token Efficiency: Reduce API costs and latency by sending fewer tokens.
  • Human Readability: Clean, tabular, and indentation-based syntax.
  • LLM Optimized: Designed to align with how models process information.
  • Schema-Aware: Improved reliability in data extraction tasks.

Getting Started

Ready to optimize your AI workflows? You can install the TOON package via npm:

npm install @toon-format/toon

When to Use TOON

Perfect For:

  • LLM Communication: Sending structured data to AI models where every token costs money
  • Uniform Data: Arrays of objects with consistent structure (databases, logs, reports)
  • High-Volume Scenarios: When processing millions of records, token savings compound
  • Context Window Optimization: Fitting more data into limited model contexts

Stick with JSON For:

  • Web APIs: JSON is the universal standard for REST/GraphQL APIs
  • Highly Nested Data: Complex, irregular structures where TOON's tabular format doesn't fit
  • Human-Edited Configs: When developers need to manually edit configuration files
  • Browser Storage: localStorage, sessionStorage expect JSON strings

TOON Syntax Deep Dive

Array Header Format

The array header [count]{keys} tells the parser:

  • How many rows to expect
  • What keys each row contains
  • What delimiter separates values

Object Format

For single objects or nested structures, TOON uses key-value pairs:


name|Alice
age|30
role|admin
                    

Nested Structures

TOON supports nested objects using indentation:


user|Alice
  profile|
    email|alice@example.com
    role|admin
                    

Real-World Example

Consider a list of 1,000 flat user records (id, name, email, role, status). Counted with the cl100k_base tokenizer in our benchmark:

  • Minified JSON: 28,250 tokens (repeated keys and punctuation)
  • TOON: 20,091 tokens (keys once in the header, then values only)
  • Difference: about 29% fewer tokens. Savings depend on how uniform your data is and how much free text it contains.

Try TOON Now

You can convert between JSON and TOON using our JSON to TOON Converter and TOON to JSON Converter. These tools help you:

  • Compare JSON and TOON output side by side
  • Test different delimiter modes
  • Understand TOON syntax through examples
  • Convert data for use in AI workflows

Conclusion

As we build more complex AI agents and applications, efficiency becomes critical. TOON offers a pragmatic solution to the token bloat problem, helping you fit more data into the same context budget. While JSON remains the standard for web APIs, TOON is worth considering for LLM prompts that carry large, uniform tables. Check the round trip on your own data first.

Start optimizing your AI workflows today. Measure the token difference on your own data, then decide whether it is worth the switch.

Written by

Spotted a mistake? Let me know