TOON vs JSON: A Benchmark of Token Savings
Measured token counts for TOON versus minified and pretty-printed JSON on user, transaction and catalog data, with the limits of the converter stated plainly.
TOON (Token-Oriented Object Notation) promises fewer tokens than JSON for uniform data. This post measures how many, using the same converter that powers our JSON to TOON tool, and is just as clear about what the numbers do not show.
Methodology
- Data: three synthetic datasets generated with a seeded random number generator, so the run is repeatable: a user directory (
id,name,email,role,status), financial transactions (id,date,account,amount,currency,category), and a product catalog wrapped in an object (store,currency, and aproductsarray). Each was generated at 10, 100 and 1,000 items. - Formats: minified JSON, pretty-printed JSON (2-space indent), TOON with the default pipe delimiter, and CSV for comparison.
- Counting: tokens counted with the open-source
gpt-tokenizerpackage using thecl100k_baseencoding. The same run witho200k_basegave savings within about one percentage point of the figures below. - Fidelity check: every TOON output was converted back to JSON and compared with the original. All nine runs round-tripped exactly.
import { encode } from "gpt-tokenizer/encoding/cl100k_base";
const count = (text) => encode(text).length;
count(JSON.stringify(data)); // minified JSON
count(JSON.stringify(data, null, 2)); // pretty-printed JSON
count(jsonToToon(JSON.stringify(data))); // TOON (pipe delimiter)Results
Token counts with cl100k_base. The last two columns show how many fewer tokens TOON uses than minified and pretty-printed JSON.
| Dataset | Items | Min. JSON | Pretty JSON | TOON | CSV | vs min. JSON | vs pretty JSON |
|---|---|---|---|---|---|---|---|
| User directory | 10 | 284 | 473 | 213 | 177 | 25% | 55% |
| User directory | 100 | 2,832 | 4,731 | 2,023 | 1,717 | 29% | 57% |
| User directory | 1,000 | 28,250 | 47,249 | 20,091 | 17,187 | 29% | 57% |
| Transactions | 10 | 367 | 586 | 269 | 251 | 27% | 54% |
| Transactions | 100 | 3,632 | 5,831 | 2,544 | 2,420 | 30% | 56% |
| Transactions | 1,000 | 36,320 | 58,319 | 25,333 | 24,154 | 30% | 57% |
| Product catalog (nested) | 10 | 279 | 480 | 199 | 168 | 29% | 59% |
| Product catalog (nested) | 100 | 2,673 | 4,584 | 1,783 | 1,623 | 33% | 61% |
| Product catalog (nested) | 1,000 | 26,554 | 45,565 | 17,565 | 16,141 | 34% | 61% |
What the numbers say
- Against minified JSON, TOON saved roughly 25-34% of tokens on these datasets. That is the fair comparison if you already minify before sending.
- Against pretty-printed JSON, it saved roughly 54-61%. Much of that gain comes from indentation and line breaks that JSON allows but TOON does not need, so the headline figure depends heavily on which JSON you compare with.
- The saving grows a little with size and then levels off. The 10-item runs saved 25-29%; the 100- and 1,000-item runs saved 29-34%. It does not stay constant at every size, and it is not a fixed percentage.
- CSV used 5-17% fewer tokens than TOON on flat rows. TOON earns its place when you also need a header that carries the array length, nested objects around the table, or a single format for tables and metadata.
Where the savings come from
In JSON, every object in an array repeats every key, wrapped in quotes and braces. In TOON's table form, the keys appear once in a header and each row carries only values. Here is the same three-row user list in both forms:
[{"id":1,"name":"Ethan Olsen","email":"ethan.olsen0@example.com","role":"editor","status":"active"},
{"id":2,"name":"Lucas Garcia","email":"lucas.garcia1@example.com","role":"billing","status":"active"},
{"id":3,"name":"Nora Rossi","email":"nora.rossi2@example.com","role":"admin","status":"pending"}][3]{id|name|email|role|status}|
1|Ethan Olsen|ethan.olsen0@example.com|editor|active
2|Lucas Garcia|lucas.garcia1@example.com|billing|active
3|Nora Rossi|nora.rossi2@example.com|admin|pendingThe more rows you have, the more repeated keys and punctuation TOON removes. The values themselves (names, emails, amounts) cost the same in every format, which is why the saving levels off instead of growing without limit.
How the converter handles edge cases
The benchmark above uses flat rows of strings, numbers and booleans, where TOON's table form applies. Other shapes still convert without losing data, but they cost more tokens or give no saving at all. The converter is tested by converting random JSON to TOON and back, in all three delimiter modes, and comparing the result with the original.
- Arrays or objects inside table rows: a table cannot hold them, so that whole array is written as inline JSON. You keep the data, but not the saving.
- Arrays whose items have different keys: also written as inline JSON.
- Values that contain the delimiter: written as quoted strings, so
a|bin a pipe-delimited table comes back asa|b. - Strings that look like numbers, booleans or null: quoted, so
"1"stays the string"1"and does not turn into the number1. - Empty strings, padded strings and odd keys: quoted as well, which adds a few characters per affected value.
Quoting is the cost of staying lossless: the more of your values need it, the smaller the saving. For irregular or deeply nested data, minified JSON is usually the better choice.
What this benchmark does not measure
- Model accuracy. We did not test how well language models read or answer questions about TOON compared with JSON. Fewer tokens is not proof of equal comprehension. Test that on your own prompts and model.
- Other tokenizers. We counted two OpenAI encodings. Other model families tokenize differently and will produce different percentages.
- Real-world data. The datasets are synthetic. Long free-text fields dilute the saving, because the text costs the same in either format.
- Money. We did not estimate dollar savings, since prices change by model and provider. The calculation is simple: tokens saved per request, multiplied by your monthly request volume and your provider's current price per token.
When TOON is worth it
- Large, uniform arrays of flat records, such as rows from a database query, that you send to a model repeatedly.
- Prompts that are near a context limit, where a 25-30% reduction in data tokens makes a difference.
- Cases where you can verify the round trip and control the delimiter.
It is a poor fit for single objects, irregular or deeply nested structures, and anything that people edit by hand. See the data serialization guide for how TOON compares with JSON, YAML, XML and CSV, and the TOON introduction for the syntax.
Frequently Asked Questions
How much does TOON reduce tokens compared with JSON?
On our test data, about 25-34% against minified JSON and about 54-61% against pretty-printed JSON. Your result depends on how uniform your data is and how much of it is free text.
Is TOON smaller than CSV?
No. On flat tables CSV used 5-17% fewer tokens in these runs. TOON adds structure, such as the length header and nesting around tables, that CSV cannot express.
Can I reproduce these numbers?
Yes. Generate seeded data in the three shapes above, convert it with the converter, and count tokens with the snippet in the methodology section. Exact counts depend on your data, but the percentages should land in the same range.
Is it safe to convert any JSON to TOON?
The converter is built to round-trip any valid JSON, and it is tested that way on random data. Even so, convert the output back with the TOON to JSON converter and compare it with your original when the data matters. Irregular shapes may use more tokens than JSON, not fewer.
Written by Kashyap Thakar
Spotted a mistake? Let me know