How This Tool Converts JSON to TOON
- Uses 2-space indentation. Each object key becomes
key: valueon its own line. - Uniform arrays of objects (all elements share the same keys, all field values are scalars) collapse into compact tabular form:
users[2]{id,name}:followed by one comma-separated row per item. - Mixed or non-uniform arrays fall back to a dashed-list form (
- a: 1) so structure is preserved without forcing a tabular shape that doesn't fit. - Strings are emitted bare when safe and quoted when they contain TOON-special characters (
: , # [ ] { } " \n \t), have leading/trailing whitespace, are empty, or look like a literal (null,true,false, a number).
When to Use JSON to TOON
- When you send the same JSON shape repeatedly to an LLM — agent tool calls, RAG context, batch evaluations — and the repeated keys add up in token cost.
- When you want to fit more data into a fixed context window without changing the underlying schema.
- When you are designing prompts that include arrays of records (user lists, product catalogs, log lines).
- Not for production APIs, machine-to-machine integration, or anywhere you need broad ecosystem tooling — JSON remains the right choice there.
TOON Syntax Reference
TOON produces one of four output patterns depending on the shape of your JSON. Knowing which pattern applies helps you predict how much the output will shrink before you convert.
Plain objects → key: value pairs
Every key in a JSON object becomes an indented key: value line. Nesting adds 2 spaces per level. String values that contain special characters (: , # [ ] { }), look like literals (null, true, false, or a number), or have leading/trailing whitespace are automatically quoted to preserve their meaning.
// JSON
{"service":"api-gateway","active":true,"rate":600}
// TOON
service: api-gateway
active: true
rate: 600
Uniform arrays of objects → tabular form
This is where TOON delivers its largest token savings. When every element in an array shares the exact same keys and all field values are scalars, TOON collapses the entire array into a compact header-plus-rows structure. Field names are stated once in the header; each subsequent line is a row of comma-separated values — no key repetition, no structural punctuation per row.
// JSON — field names repeat on every object
[{"id":1,"name":"Alice","role":"admin"},{"id":2,"name":"Bob","role":"viewer"}]
// TOON — field names stated once
[2]{id,name,role}:
1,Alice,admin
2,Bob,viewer
Scalar arrays → inline list
Arrays that contain only scalars (strings, numbers, booleans, nulls, or any mix of them) are rendered on a single line. Values that require quoting get JSON.stringify-style quotes; safe bare values are emitted without quotes.
// JSON
{"tags":["alpha","beta","gamma"]}
// TOON
tags: [alpha, beta, gamma]
Mixed or non-uniform arrays → dashed list
When an array contains objects with differing key sets, or when any field value is itself an object or array (making a true tabular structure impossible), TOON falls back to a dashed-list form. This preserves the full structure without forcing a tabular shape that doesn’t fit the data.
// JSON — objects have different key sets
[{"a":1},{"b":2,"c":true}]
// TOON
- a: 1
- b: 2
c: true
How TOON Reduces LLM Token Costs
Large language model APIs charge per token, and every repeated JSON key in your prompt is tokens you pay for. When you send a list of 50 user records where each record has 8 fields, those 8 field names appear 50 times in plain JSON — that is 400 redundant key tokens before the model reads a single value. TOON states the field names once in the header row and then outputs only values, eliminating that repetition entirely.
The savings scale with the size and uniformity of your data. A repetitive product catalog, a batch of RAG context snippets, or a list of agent tool-call results can all compress significantly. The savings indicator that appears below the output after each conversion gives you a precise character-count measurement for your specific payload. The estimated token range uses OpenAI’s o200k_base BPE tokenizer as a representative reference — actual reduction varies by model provider and content vocabulary. Always validate with your own tokenizer before making cost projections.
TOON is most effective when you control both ends of the pipeline: your code generates the TOON-formatted prompt and the receiving LLM (or your post-processing code) knows to expect it. It is not a drop-in replacement for JSON in REST APIs or any system where the consumer expects standard JSON. For those use cases, the JSON Minifier is a better fit — it strips whitespace while keeping the payload valid JSON.
Frequently Asked Questions
What is TOON format?
TOON (Token-Oriented Object Notation) is an emerging experimental serialization style designed to reduce the token cost of sending structured data to large language models. It uses YAML-style indentation and collapses arrays of uniform objects into a compact header-plus-rows form. TOON is not an industry standard or a replacement for JSON in APIs. See the full guide for a deeper explanation.
How do I convert JSON to TOON with this tool?
Paste valid JSON into the left textarea (or click Load Example), then click Convert to TOON. The TOON output appears on the right. Use Copy to put it on your clipboard or Download to save it as a .toon file. Everything runs in your browser.
Will TOON actually reduce my OpenAI or Anthropic token bill?
It depends on your payload and the tokenizer. Highly repetitive arrays of objects (where the same field names appear over and over) typically see the biggest reductions because TOON collapses the keys into one header row. Small payloads, deeply nested non-uniform structures, and payloads with little repetition may not benefit. Always measure with your own tokenizer before relying on a number.
Does this tool send my JSON to a server?
No. The conversion runs entirely in your browser using client-side JavaScript. Your JSON never leaves your device.
Can I convert TOON back to JSON?
Not in this tool. The converter is one-way (JSON to TOON) today. If you need a TOON parser, you can either keep your original JSON or use one of the third-party TOON libraries that are starting to appear.