MyWebUtils
JSON ↔ TOON Converter
Convert data between JSON and the human-readable TOON format.
(0 tokens)
(0 tokens)
A Developer's Guide to TOON (Token-Oriented Object Notation)

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's 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, viewer

What just happened?

  • Instead of writing "id" and "name" three separate times, TOON writes them once in a header {}id,name,role}. No repeated keys.
  • All the brackets and structural commas are gone. Just the data.
  • The [3] tells the LLM exactly how many items to expect, which actually helps the model 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:

  • Since LLMs bill by the token, cutting your data size by 30-50% directly cuts your monthly invoice. If you're regularly sending long lists of products, logs, or user history to ChatGPT, the savings add up fast.
  • Fewer tokens means the model processes your prompt faster. That reduced latency is noticeable in production apps where response time matters.
  • LLMs have a "memory limit" — the context window. By compressing your data with TOON, you fit more information into that window without confusing the model. You're not losing data; you're just packing it more efficiently.

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 work just like YAML: key: value.
  • Simple lists (arrays) use a hyphen - for each item.
  • Tables are where TOON really shines. For a list of objects that all share the same keys, it uses a special table syntax:
    key[length]{header1,header2}:
      value1, value2
    That single header line replaces dozens of repeated keys. It's the main source of TOON's token efficiency.
  • Nesting works through indentation — deeper data just gets indented further to the right.

TOON vs. Other Formats

FeatureTOONJSONYAMLCSV
Primary UseLLM PromptsAPIs, WebConfig FilesSpreadsheets
Token EfficiencyVery HighLowMediumHigh (but limited)
ReadabilityHighLow (when minified)Very HighMedium
Nested DataYesYesYesNo

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 paste the output directly into your prompt, something like "Here is the user data in TOON format: [paste data]..." LLMs are very good at reading patterns, so they handle TOON naturally without any special training or system prompting.

Do I need a special library to parse TOON in my code?

You do, yes — same as you'd use a library to parse JSON or YAML. The official TOON libraries cover JavaScript/TypeScript (@toon-format/toon) and Python (toon-py), with more in development. They give you an encode() function to turn objects into TOON strings and a decode() to go the other way.

Does TOON replace JSON?

No, and it's not trying to. JSON is the right choice for API requests and machine-to-machine communication — it's universally supported and well understood. TOON's job is specifically to pack structured data more efficiently when you're sending it to a Large Language Model. Different tool for a different problem.

How does TOON handle nested data?

Through indentation, similar to how YAML works. If an item inside a TOON table is itself an object or array, it gets rendered on a new line with more indentation. The structure stays intact — it's just expressed more compactly.

Is this JSON to TOON converter secure?

Yes. Everything runs in your browser — client-side only. Your data never touches our server or any third party. You can safely convert private or sensitive information without concern.

What's the difference between TOON and YAML?

They look similar because both use indentation, but they're solving different problems. YAML is designed for human-written configuration files and has a lot of flexibility (sometimes too much). TOON is simpler and specifically optimized for representing lists of similar objects as compact tables — which is exactly the kind of data you're typically feeding to an LLM.

Will I lose data during conversion?

No. The conversion is lossless for standard data types. Numbers, strings, booleans, and arrays all come through intact. You can convert JSON to TOON and back to JSON without any data loss.

Can I add comments to a TOON file?

Yes — TOON supports comments using the # symbol, just like YAML or Python. Any line starting with # gets ignored by the parser, so you can add notes or context to your data without it affecting anything.

Does it work with non-English characters?

Fully. TOON supports Unicode, so emojis, accented characters, and non-Latin scripts all work without any special handling.

Is TOON an official standard?

It's a modern, open-source specification — not an IETF standard like JSON, but it has a formal spec and a growing library ecosystem. For production use cases where you're optimizing LLM interactions, it's a reliable and well-defined choice.

How is the "token count" on this page calculated?

It's an estimate. For JSON, the count includes keys, values, and structural characters ({}}, [], :, ,). For TOON, it counts keys and values. That gives a reasonable proxy for how an LLM would tokenize the data. The actual numbers can vary slightly between models — GPT-4 tokenizes a bit differently than Claude — but the directional savings are real and consistent.

More Data Tools Tools