Same 12 Repos, 8 Formats: 1,813 Tokens as Pretty JSON
Tool results go into the prompt already pretty-printed, and the same data in a flat format would cost 45% fewer input tokens on every turn.
📜 Table of Contents
- What was counted
- The 12-repository payload, format by format
- Where the tokens actually go
- Two more payloads, to check the ratios hold
- Why tab-separated lost to comma-separated
- When comma-separated is the wrong answer
- The rules this measurement supports
- The two lines that do most of the work
- What this does not show
- FAQ
Twelve GitHub repository records, the same eleven fields each time, serialised eight ways and counted with two encoders. Pretty-printed JSON costs 1,813 tokens. Compact JSON costs 1,232. CSV costs 993. Nobody changed the data, only the punctuation and the shape.
Tool results arrive in whatever shape the tool author chose, and that shape sits in the prompt on every turn of a loop. Counting it is cheap, and the gap is large enough to be worth a decision.
What was counted
Three payloads, all fetched live on 2026-11-24, none invented:
- 12 repositories pulled one by one from the GitHub REST API, keeping name, stars, forks, open issues, language, licence, size in KB, created date, last push date, description truncated to 180 characters, and up to six topics. This is the messy case: strings, integers, dates, a nested list, and a null licence.
- 10 models from the Hugging Face models endpoint sorted by downloads, keeping id, downloads, likes, pipeline tag, created date and up to six tags.
- A five-column numeric table built from the same 12 repositories: name, stars, forks, open issues, size. No prose, no lists, no nulls.
Each payload was written eight ways: JSON with two-space indentation, compact JSON, newline-delimited JSON, CSV as the Python csv module writes it, the same CSV with tabs instead of commas, a markdown table, one line of key=value pairs per record, and a small YAML block. Tokens were counted with tiktoken, the cl100k_base and o200k_base encodings, no special tokens added. No model was called, so nothing here is a quality claim.
The 12-repository payload, format by format
| format | bytes | cl100k tokens | o200k tokens | vs pretty JSON |
|---|---|---|---|---|
| JSON, 2-space indent | 5,829 | 1,813 | 1,825 | baseline |
| JSON, compact | 4,461 | 1,232 | 1,243 | -32.0% |
| NDJSON, one record per line | 4,459 | 1,231 | 1,243 | -32.1% |
| CSV | 3,094 | 993 | 983 | -45.2% |
| TSV | 3,094 | 1,061 | 1,052 | -41.5% |
| markdown table | 3,416 | 1,105 | 1,097 | -39.1% |
| key=value lines | 4,080 | 1,124 | 1,136 | -38.0% |
| YAML | 4,348 | 1,401 | 1,416 | -22.7% |
Two encoders agree on the ordering to within one position, which means the ratio is a property of the format and not of a particular vocabulary. The o200k encoder is consistently slightly worse on YAML and slightly better on CSV, a difference of under 2 percent in both directions.
Where the tokens actually go
In compact JSON the eleven key names appear once per record. Measured on their own, those key tokens plus their colons come to 37 per record, or 444 across twelve records: 36.0 percent of the 1,232-token payload is the field names being repeated.
CSV pays that cost once, as a header, and then writes values only. It also drops the quotes and braces around every field, which is why the drop is larger than 36 percent. On this payload the csv module added quotes around descriptions that contain commas, and that clawed some of it back.
JSON with two-space indentation is the expensive one: 581 extra tokens over compact JSON, a 47.2 percent increase, all of it whitespace. Every level of nesting doubles the indent, and this payload nests twice.
Two more payloads, to check the ratios hold
| format | 10 HF models (cl100k) | 12 x 5 numeric table (cl100k) |
|---|---|---|
| JSON, 2-space indent | 997 | 595 |
| JSON, compact | 648 | 367 |
| NDJSON | 646 | 377 |
| CSV | 593 | 231 |
| TSV | 654 | 231 |
| markdown table | 652 | 303 |
| key=value lines | 629 | 299 |
| YAML | 731 | 459 |
The same ordering holds three times. Two numbers move, and both are useful. First, the pretty-print penalty grows with the number of rows and the depth of nesting: 47.2 percent on the repository payload, 53.9 percent on the model list, 62.1 percent on the pure numeric table. Second, CSV's advantage shrinks as the values get wordier: 61.2 percent on the numeric table, 45.2 percent on repositories, 40.5 percent on the model list.
Markdown tables land 31 percent above CSV on the numeric payload and 11 percent above it on the repository payload, while staying legible to a human reading the transcript. That is the tradeoff worth knowing: markdown is the readable middle, not the cheapest option.
Why tab-separated lost to comma-separated
Both separators are one byte, so the 68-token gap on the repository payload is about how the encoder merges characters, not about size. Text interrupted by tabs breaks into smaller pieces than the same text interrupted by commas, and words that tokenise as one piece beside a comma split in two beside a tab. The effect appears only on prose. On the numeric table, tab-separated and comma-separated are identical at 231 tokens, because digits tokenise the same either way.
So the rule is narrow: tabs help nothing, and they cost something when descriptions sit in the columns.
When comma-separated is the wrong answer
It won on all three payloads and is still the wrong choice for a general tool result, for four reasons visible in this data.
- Nesting. The topics field is a list, and it flattened into a quoted string. A model reading it back has to parse the string itself.
- Nulls and type loss. The licence field is null for some records. In a flat file that becomes an empty cell, indistinguishable from an empty string, and every number becomes text.
- Escaping cost. Descriptions with commas forced quoting, which ate into the saving. Text with many commas and quotes can push the flat file above compact JSON.
- Contract by position. A reader that expects five columns misreads a six-column row without complaint. JSON names its fields on every record, which is exactly the redundancy that costs 36 percent.
What survives all four is a homogeneous table with short values, and that is where the 61.2 percent saving came from.
The rules this measurement supports
- Never put indented JSON in a prompt. It was the most expensive option on every payload measured here, and the whitespace carries no information the parser needs.
- Default to compact JSON for records with mixed types, nested lists or nulls. It keeps field names, which is what makes a tool result self-describing.
- Switch to comma-separated or a markdown table when the result is a flat table with uniform rows and short values. On the numeric payload that choice is worth 6,400 tokens per 100 calls at the size above.
- Use NDJSON when tool results stream in as they arrive; it counts the same as compact JSON and parses line by line.
- Skip YAML for prompt payloads. It came 13.7 percent above compact JSON on the repository payload and 25.1 percent above it on the numeric table, and it adds indentation rules the model has to infer.
The two lines that do most of the work
For JSON, the expensive and the cheap version differ by one argument:
json.dumps(rows, separators=(chr(44), chr(58))) writes compact JSON: no space after the separator, no indentation. Dropping the indent alone removed 581 tokens from the payload above.
For a flat table, fix the column order once and write values only: take cols = list(rows[0].keys()), write one header line, then one line per record with comma-joined values. The csv module handles quoting and is the safer default when strings may contain commas.
Measure your own payload before and after with the same counter, because the ratio depends on how wordy the values are. Counting prompt tokens is four lines of Python and no API key.
What this does not show
No model was asked to read these payloads, so nothing here says comma-separated data is answered as accurately as JSON. Reading accuracy is a separate experiment, and a format that saves 45 percent of the input tokens is worth nothing if it costs one wrong row. The counts also come from two encodings, not from every model family; a different vocabulary moves the absolute numbers, though the ordering held across both encoders here.
The input side of the same bill is in the MCP tool schema measurement, where 37 tool definitions cost 8,038 tokens before a single result arrives. What the same text costs in other languages is in the four-language tokenizer test. What this arithmetic does at index scale is in the million-chunk sizing post.
FAQ
Is indented JSON really 47 percent more expensive? On this payload, yes: 1,813 tokens against 1,232 for the same records with the same field names. The penalty grows with nesting depth and row count, and reached 62.1 percent on the pure numeric table.
Does a flat file work for nested tool results? It flattens them into quoted strings. The model then has to parse the string, and a null becomes an empty cell. Keep JSON when the data nests.
Why not just cut long fields short? Cutting fields short and choosing a format are independent levers. Descriptions here were capped at 180 characters, and the format choice still moved the count by 820 tokens.
Which encoder should I trust? Both moved together. cl100k and o200k disagreed by at most 18 tokens on any row of the repository payload, and the ranking of the eight formats was identical to within one position.
Written by our editorial team; tools listed here are tested or verified against public sources. Links point to official sites or GitHub repos for reference only — no paid placements.