June 12, 2026 · 1 min read · Yunus Emre Vurgun

The Cost of Pretty-Printing JSON in Prompts

json · tokens · prompting · formatting
In this guide
  1. The measurement
  2. What you save by compacting
  3. When pretty-printing is fine
  4. The fix

Pretty-printing JSON is the default in most developer tools. It is also a quiet tax on every prompt that includes JSON. The cost is small per blob and large over a month.

The measurement

Three encodings of the same 5KB payload, tokenized with cl100k_base:

  • Compact: 1,820 tokens.
  • Two-space indent: 2,460 tokens (35% more).
  • Four-space indent: 2,910 tokens (60% more).

What you save by compacting

For a system prompt that includes a 5KB JSON reference, switching from two-space to compact saves ~640 tokens. At GPT-4o input pricing, that is roughly $0.0016 per request. Over a million requests a day, that is $1,600/day, or about $580K/year.

When pretty-printing is fine

When the JSON is shown to a human in a tool UI. When the prompt is short and will not be repeated. When you are debugging and the readability helps.

The fix

Keep the pretty-printed version for humans. Keep a compact version next to it, named with a .min.json suffix, and use that in prompts. The compact form parses identically; the tokens do not know the difference.

Search the library

Search by a topic, title, or keyword.

Start with a collection

Browse all 205 datasets