Same 12 Repos, 8 Formats: 1,813 Tokens as Pretty JSON

🔧 AI Tools 2026-11-24 7 min read

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

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:

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

formatbytescl100k tokenso200k tokensvs pretty JSON
JSON, 2-space indent5,8291,8131,825baseline
JSON, compact4,4611,2321,243-32.0%
NDJSON, one record per line4,4591,2311,243-32.1%
CSV3,094993983-45.2%
TSV3,0941,0611,052-41.5%
markdown table3,4161,1051,097-39.1%
key=value lines4,0801,1241,136-38.0%
YAML4,3481,4011,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

format10 HF models (cl100k)12 x 5 numeric table (cl100k)
JSON, 2-space indent997595
JSON, compact648367
NDJSON646377
CSV593231
TSV654231
markdown table652303
key=value lines629299
YAML731459

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.

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

  1. 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.
  2. 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.
  3. 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.
  4. Use NDJSON when tool results stream in as they arrive; it counts the same as compact JSON and parses line by line.
  5. 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.

Related Articles
2026-08-20
Best AI Customer Support Chatbot in Chennai 2026: 6 Tools for IT Services and BPO
2026-08-16
AI Cover Letter Generator Free 2026: 7 Tools That Beat the ATS
2026-08-16
Best AI Translation Tool in Dubai 2026: 6 Tools for the City of 200 Nationalities
2026-08-10
AI Database Tools 2026: Talk to Your SQL Database in Plain English
2026-08-28
Best AI Bedtime Story Generator in 2026: 6 Free Tools for Parents of Picky Sleepers
2026-07-11
OpenClaw 5.28: Security Fences Bolted Shut, Video Generation Built Right In - Deep Dive

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.

💬 Comments (0)

No comments yet. Be the first!

Login to comment