Skip to content
Mock and Match

Transform - JSON → TOON

Converts a JSON into TOON (Token-Oriented Object Notation), a compact format for reducing tokens in LLM prompts. Fully processed in your browser.

Runs locally
Transformation

Options

Input

Loading editor...

Output

Click "Transform" to see the result here.

What the TOON format is

TOON (Token-Oriented Object Notation) is a text format for representing the same data as a JSON, designed to use fewer tokens when that text is sent inside a prompt to a language model (LLM). Tokens are the unit services like ChatGPT or Claude bill and cap — the fewer tokens a prompt uses, the cheaper it is and the more room is left for the rest of the conversation.

JSON spends a good chunk of those tokens on punctuation that repeats: braces, brackets, quotes around every piece of text and, in a list of similar objects, each field's name copied in every item. TOON removes that repetition.

How it works

The core idea: when a list has several objects with the same fields, TOON writes the field names once, in a header, and each item becomes a single line with just the values, separated by commas, like a CSV table. For nested objects, it uses indentation, YAML-style.

Input (JSON, uniform list)
{
  "users": [
    { "id": 1, "name": "Ana", "role": "admin" },
    { "id": 2, "name": "Beto", "role": "user" },
    { "id": 3, "name": "Cátia", "role": "user" }
  ]
}
Output (TOON)
users[3]{id,name,role}:
  1,Ana,admin
  2,Beto,user
  3,Cátia,user

In this example, the JSON is 167 characters and the TOON is 66 — about 60% smaller (this page's character count, computed with the real converter; the token savings for an LLM usually range between 30% and 60%, per the format's spec, varying with the size and shape of the data).

  • users[3] says the list has 3 items — the model (and whoever's reading) knows upfront how many rows to expect, which helps catch a missing item.
  • {id,name,role} is the header: each field's name appears once, not in every item.
  • Every line after that is one item, in the same order as the header's fields.

Irregular or deeply nested data

Not every JSON fits that table shape. When a list's items have different fields from each other, TOON falls back to a plain list form (one line per item, no table) — still a valid, lossless conversion, just with much less token savings:

Input (JSON, items with different fields)
{
  "events": [
    { "type": "login", "userId": 1 },
    { "type": "purchase", "userId": 2, "amount": 49.9, "coupon": "PROMO10" },
    { "type": "logout", "userId": 1, "durationMin": 12 }
  ]
}
Output (TOON, list form)
events[3]:
  - type: login
    userId: 1
  - type: purchase
    userId: 2
    amount: 49.9
    coupon: PROMO10
  - type: logout
    userId: 1
    durationMin: 12

When to use it (and when to avoid it)

  • Worth it: large, uniform lists (same fields in every item) inside a prompt for an LLM — search results, spreadsheet rows, database records, a history of similar events.
  • Small gain: deeply nested data, lists with few items, or items with an irregular shape.
  • Don't use it: to talk to an API, save to a database, or anywhere that expects real JSON — TOON is meant for the text inside the prompt, not as a replacement for JSON as an integration format.

An example use inside a prompt

Here is the list of active users:

users[3]{id,name,role}:
  1,Ana,admin
  2,Beto,user
  3,Cátia,user

List the users with the "user" role.

How to use this tool

  1. Choose JSON → TOON to compress a JSON before pasting it into a prompt, or TOON → JSON for the reverse (for example, if a model replied in TOON and you want the JSON back).
  2. Paste the content into the input field and click Transform.
  3. Under Options, you can switch the column delimiter (comma, tab or pipe) — useful if your data already uses commas inside the values.

Frequently asked questions about TOON

Is TOON an official format, maintained by whom?

It's an open, independent specification (not from OpenAI, Google or Anthropic), published under the MIT license at github.com/toon-format/spec. Like any text format, you can use it without depending on any service.

Do I need to explain the TOON format for the AI model to understand it?

It helps to include a short sentence explaining the notation the first time it appears in the conversation (something like "the data below is in TOON: array[N]{fields} followed by one comma-separated line per record"). Current models usually understand TOON well even without that explanation, but it reduces the risk of misreading.

Is the TOON → JSON conversion really lossless?

Yes, that's the format's whole point: the same objects, arrays and primitive values as the JSON, including text, numbers, true/false and null. In this tool, the encoder and decoder are automatically tested going from JSON to TOON and back, checking that the final result is identical to the original.

Does it work with any JSON, even nested or irregular?

Yes, but the token savings mainly come from uniform lists (same fields in every item), converted into the tabular form. Lists with items of different shapes, or deeply nested data, fall back to a line-by-line form — still a valid conversion, just with much smaller savings.

Why not use TOON instead of JSON everywhere?

Because APIs, databases, and practically every tool expect JSON. TOON is meant for the text you send inside a prompt to an AI model, not as a replacement for JSON as the data-interchange format between systems.

What Transform is for

Transform converts data and code from one format to another without leaving your browser. Paste a JSON and get back the matching TypeScript interfaces, Zod schema or JSON Schema; convert config files between YAML, JSON and TOML; turn CSS into Tailwind classes. Everything is processed locally, without sending your content to any server.

How to use it

  1. Click the Transformation picker and choose the conversion. You can search by name, and your recently used and favorited ones stay within reach.
  2. Paste the content into the Input field (or use the Paste button). For JSON, the Format button indents the text.
  3. If the conversion has options, like the root type's name, adjust them in the panel above the editors.
  4. Click Transform. The result appears in Output, where you can copy it or download the file.

Example: JSON to TypeScript

The JSON → TypeScript conversion reads the JSON's structure and generates an interface for each object, including nested ones. This is the tool's real output for the JSON below:

Input (JSON)
{
  "id": 1,
  "name": "Ana Souza",
  "email": "ana@example.com",
  "active": true,
  "tags": ["admin", "beta"],
  "address": { "city": "São Paulo", "zip": "01310-100" }
}
Output (TypeScript)
interface Address {
  city: string;
  zip: string;
}

interface User {
  id: number;
  name: string;
  email: string;
  active: boolean;
  tags: string[];
  address: Address;
}

Need to validate the data at runtime, not just type it? The same input can become a Zod schema by choosing JSON → Zod in the picker.

Available conversions

JSON

TOON

  • JSON → TOONConverts a JSON into TOON (Token-Oriented Object Notation), a compact format for reducing tokens in LLM prompts.
  • TOON → JSONConverts TOON (Token-Oriented Object Notation) back into JSON, losslessly.

YAML

XML

TypeScript

CSS

  • CSS → TailwindConverts CSS properties into Tailwind (v3.1+) utility classes, using arbitrary values when there's no exact class.
  • CSS → JS ObjectConverts CSS into a JavaScript object of styles (React inline styles / styled-components).
  • CSS → Template LiteralWraps the CSS in a `css`...`` template literal (styled-components / emotion), reformatted.

Before using the result

Review what was generated

Types and schemas are inferred from a single example. They're a great starting point, but they don't replace your API's official contract: check optional fields, null values and unions before shipping to production.

Frequently asked questions

Is my data sent to any server?

No. Conversion happens in your browser, and whatever you paste or type is never sent anywhere. For conversions involving TypeScript, the compiler is downloaded from the site itself the first time you use it — only the compiler's own code is downloaded, your content never leaves the browser.

Which conversions are available?

17 conversions: from JSON to TypeScript, Zod, JSON Schema, YAML, XML, GraphQL and TOON (the compact format for LLM prompts); from TOON back to JSON; from YAML to JSON and TOML; from XML to JSON; from TypeScript to JavaScript, Zod and JSON Schema; and from CSS to Tailwind classes, a JavaScript object, and a template literal.

What's the maximum content size?

The input field accepts up to 10,000,000 characters. If you paste something larger, the tool warns you about the size and pastes nothing, so the browser doesn't freeze.

Why does my JSON throw an error?

The error message points to the exact position of the problem (line and column). The most common causes are single quotes instead of double quotes, a trailing comma after the last item, unquoted keys, and comments — none of which the JSON format allows.

How does Transform handle lists with different objects?

When a list's items have different shapes, the tool generates a type for each shape and combines them into a union (for example, Order | Order1). If you'd rather have a single type with optional fields, adjust it manually after generating.

Are the generated types final?

They're inferred from the example you provide. A null field in the example becomes null, an empty list becomes unknown[], and a field missing from some items isn't marked optional. Use a representative example and review the result before using it in production.

Does the TypeScript → Zod conversion cover everything?

It preserves objects, arrays, optional fields (key?: T or T | undefined), nullable values (T | null becomes .nullable()), literal-value unions (become z.enum) and type aliases used in the interfaces. Still simplified to z.unknown() are generics, TypeScript utility types (Partial, Pick, Record), intersections (&), tuples, TypeScript enums, and the Date type. Review the generated schema.

Is the tool free?

Yes, it's free and requires no sign-up or account.