MyWebUtils: Free Online Dev Tools
What is TOON and Why Use It?
If you are working with LLMs like GPT-4, Claude 3.5, and Gemini, you know that "tokens" are money. The more tokens you send, the more you pay, and the slower your model responds.
TOON is a modern data serialization format designed specifically to fix the "bloat" of JSON.
Standard JSON is great for APIs, but it is heavy on syntax. It repeats keys for every single item in a list and uses tons of braces `{}`, quotes `""`, and commas. TOON strips all that noise away. It combines the clean look of YAML (indentation) with the density of CSV (tables) to make your data up to 50% smaller in token count.
See the Difference (JSON vs. TOON)
The best way to understand TOON is to see it. Look at how much cleaner and more compact the TOON version is for a simple list of users.
Input (Standard JSON)
~65 tokens
{
"users": [
{ "id": 1, "name": "Alice", "role": "admin" },
{ "id": 2, "name": "Bob", "role": "editor" },
{ "id": 3, "name": "Charlie", "role": "viewer" }
]
}Output (TOON Format)
~32 tokens (50% token saving!)
users[3]{id,name,role}:
1, Alice, admin
2, Bob, editor
3, Charlie, viewerWhat just happened?
- No repeated keys: Instead of writing "id" and "name" three times, TOON writes them once in a header `{}id,name,role}`.
- No punctuation noise: The brackets and commas are gone.
- Explicit Length: The `[3]` tells the LLM exactly how many items to expect, which actually helps the AI stay on track.
Why This Tool is a Game-Changer for LLM Devs
There are three main reasons developers are switching their LLM context to TOON:
- Lower API Bills: Since LLMs bill by the token, reducing your data size by 30-50% directly cuts your monthly invoice. If you are sending long lists of products, logs, or user history to ChatGPT, this tool pays for itself.
- Faster Responses: Sending fewer tokens means the model processes your prompt faster. This reduces latency in your app.
- Better Context Management: LLMs have a "memory limit" (context window). By compressing your data with TOON, you fit more information into that memory without confusing the model.
When to Use TOON (and When Not To)
- ✅ USE IT FOR: Large lists of similar items. If you have an array of 50 products, 100 log entries, or a long transaction history, TOON is perfect. It works like a spreadsheet, compressing that repeated structure massively.
- ❌ SKIP IT FOR: Deeply nested, complex objects. If your JSON looks like a "tree" with many different levels and no repeating patterns, TOON might not save you much space compared to standard JSON.
Quick TOON Syntax Guide
TOON is simple. Here are the core concepts:
- Key-Value Pairs: Just like YAML. `key: value`.
- Lists (Arrays): Use a hyphen `-` for each item.
- Tables (The Magic Part): For a list of objects with the same keys, TOON uses a special table syntax:
key[length]{header1,header2}: value1, value2This is the key to its token efficiency. - Nesting: Deeper data is simply indented further to the right.
TOON vs. Other Formats
| Feature | TOON | JSON | YAML | CSV |
|---|---|---|---|---|
| Primary Use | LLM Prompts | APIs, Web | Config Files | Spreadsheets |
| Token Efficiency | Very High | Low | Medium | High (but limited) |
| Readability | High | Low (when minified) | Very High | Medium |
| Nested Data | Yes | Yes | Yes | No |
Getting Started with TOON in Your Project
Using TOON in your code is straightforward with the official libraries. Here’s a quick example in JavaScript/TypeScript:
import { encode } from '@toon-format/toon';
const myData = {
users: [
{ id: 1, name: "Alice", role: "admin" },
{ id: 2, name: "Bob", role: "editor" },
]
};
// Convert your object to a TOON string
const toonString = encode(myData);
// Now, include toonString in your LLM prompt
const prompt = `
Analyze the following users:
${toonString}
`;
// Send the prompt to your LLM API...
Frequently Asked Questions
Is this format compatible with OpenAI and Anthropic?
Yes. TOON is just text. You can paste the output directly into your prompt (e.g., "Here is the user data in TOON format: [paste data]..."). LLMs are very good at understanding patterns, so they read TOON naturally without needing special training.
Do I need a special library to parse TOON in my code?
Yes, just like you use a library to parse JSON or YAML. The official TOON libraries are available for major languages like JavaScript/TypeScript (`@toon-format/toon`), Python (`toon-py`), and more are in development. They make it simple to `encode()` your objects into a TOON string or `decode()` a TOON string back into your application's native objects.
Does TOON replace JSON?
No. TOON is not a replacement for JSON. JSON is an excellent, universally supported format for API requests and machine-to-machine communication. TOON's primary purpose is to be a more efficient format for sending structured data *to a Large Language Model*. Think of it as a specialized tool for LLM context, not a general-purpose data format.
How does TOON handle nested data?
TOON handles nested objects and arrays using indentation, similar to YAML. If an item in a TOON table is an object or array itself, it will be rendered on a new line with increased indentation, maintaining the structure of your data in a readable way.
Is this JSON to TOON converter secure?
Absolutely. All conversion logic runs entirely within your browser (client-side). Your data is never sent to our server or any third party, making it completely safe to use for private or sensitive information.
What's the difference between TOON and YAML?
They look similar because both use indentation, but they are optimized for different things. YAML is designed for human-written configuration files and can be quite complex. TOON is simpler and specifically optimized for token-efficient representation of lists of objects (tables), which is a common data structure sent to LLMs.
Will I lose data during conversion?
No. The conversion is "lossless" for standard data types. Numbers, strings, booleans, and arrays are preserved perfectly. You can convert JSON to TOON and back to JSON without issues.
Can I add comments to a TOON file?
Yes. TOON supports comments using the `#` symbol, just like YAML or Python. Any line starting with `#` will be ignored by the parser, which is useful for adding notes or explanations to your data.
Does it work with non-English characters?
Yes, TOON supports full Unicode, so emojis, accents, and non-Latin scripts work just fine.
Is TOON an official standard?
TOON is a modern, open-source specification. While not an IETF standard like JSON, it has a formal specification and a growing ecosystem of libraries, making it a reliable choice for production applications that need to optimize LLM interactions.
How is the "token count" on this page calculated?
The token count is an estimate. For JSON, it counts keys, values, and structural characters (`{}`, `[]`, `:`, `,`). For TOON, it counts keys and values, giving a reasonable proxy for how an LLM would tokenize the data. The actual tokenization can vary slightly between models (e.g., GPT-4 vs. Claude), but this gives a strong directional sense of the savings.