TokenSave Data · Dataset
JSON vs YAML vs CSV vs TOON: how many tokens each format costs
The same 20-product table costs 1,336 GPT tokens as indented JSON and 429 as CSV (68% fewer). CSV was the cheapest format on every tokenizer we tested (Claude, Gemini, GPT), and the newer TOON format came close but did not beat it. XML was the most expensive.
Measured 2026-10-17 · 8 formats · 4 tokenizers · License CC BY 4.0 · Related: token cost by language
DOI 10.5281/zenodo.23435788 · Also on Hugging Face · Kaggle · GitHub
Key findings
- CSV and TSV are the cheapest. Switching from indented JSON to CSV cuts tokens by 68% on GPT, 66% on Claude 5.5 and 70% on Gemini.
- TOON is close to CSV, not below it. The token-oriented format needs 10% more tokens than CSV on GPT and 4% more on Claude 5.5, while still using about two thirds fewer than indented JSON.
- Minifying JSON helps less on Claude. Removing whitespace saves 51% on Gemini and 43% on GPT but only 34% on Claude 5.5. Minified JSON is the format where Claude 5.5 needs the most extra tokens over GPT (+59%).
- Claude 5.5 uses more tokens for every format. Compared with GPT it needs 28% to 59% more for the same data, and more than Claude Haiku 4.5 as well. The jump over Haiku 4.5 is largest for minified JSON (+43%), where punctuation is packed with no spaces, matching our finding that Claude's newer tokenizer changed how Latin-script text is split.
- XML is the most expensive. It needs +20% versus indented JSON on GPT.
All 8 formats
Tokens for the same table, with the difference versus indented JSON on the same tokenizer in brackets.
| Format | Claude Opus/Sonnet 5.5 | Claude Haiku 4.5 | Gemini 3.x | GPT o200k |
|---|---|---|---|---|
| TSV | 621 (-66%) | 477 (-71%) | 483 (-70%) | 427 (-68%) |
| CSV | 620 (-66%) | 476 (-71%) | 482 (-70%) | 429 (-68%) |
| TOON | 647 (-65%) | 502 (-69%) | 508 (-69%) | 474 (-65%) |
| Markdown table | 800 (-57%) | 649 (-60%) | 590 (-64%) | 539 (-60%) |
| JSON (minified) | 1,210 (-34%) | 847 (-48%) | 791 (-51%) | 763 (-43%) |
| YAML | 1,275 (-31%) | 1,074 (-34%) | 1,076 (-34%) | 997 (-25%) |
| JSON (indented) | 1,841 (±0%) | 1,618 (±0%) | 1,623 (±0%) | 1,336 (±0%) |
| XML | 2,200 (+20%) | 1,868 (+15%) | 1,873 (+15%) | 1,603 (+20%) |
What the inputs look like
All eight files hold the same 20 products with 7 fields each (id, name, category, price, in stock, rating, tags). The full inputs are in the JSON download.
CSV
id,name,category,price,in_stock,rating,tags 1,Wireless Mouse,Electronics,24.99,true,4.5,office;wireless 2,Mechanical Keyboard,Electronics,89.0,true,4.7,office;gaming …
TOON
products[20]{id,name,category,price,in_stock,rating,tags}:
1,Wireless Mouse,Electronics,24.99,true,4.5,office|wireless
2,Mechanical Keyboard,Electronics,89.0,true,4.7,office|gaming
…JSON (indented)
{
"products": [
{
"id": 1,
"name": "Wireless Mouse",
"category": "Electronics",
…Method
- One table of 20 products × 7 fields, written out in 8 formats: indented JSON (2 spaces), minified JSON, YAML, XML, CSV, TSV, a Markdown table and TOON (tabular form, tags joined with |).
- Claude: each file sent through Claude Code (
claude -p) with a fixed one-line system prompt; reported input tokens minus the same run with a one-character message. Opus 5.5 and Sonnet 5.5 gave identical counts. - Gemini: Google AI Studio prompt token counter on Gemini 3.8 Flash, minus its one start token. XML, CSV and indented JSON were measured a second time with a stricter reading of the counter; CSV and JSON matched, and the XML value shown is from the second run.
- GPT: tiktoken with
o200k_base.
Limitations
- One flat table. Deeply nested data does not fit CSV well, and there JSON or YAML may be the practical choice.
- Token count is not the only factor: models may read some formats more reliably than others. This dataset measures cost only.
- Claude values can be off by about ±2 tokens; with tables of 400+ tokens that is under 1%.
How to cite
Free to use, quote and republish with attribution under CC BY 4.0. Please link to this page.
TokenSave (2026). Token cost by data format: JSON vs YAML vs CSV vs TOON on Claude, Gemini and GPT [Data set]. Zenodo. https://doi.org/10.5281/zenodo.23435788
Embed the chart
Related
Questions or corrections: contact@jonhisking.com