Skip to main content

Structured Data Token Overhead

JSON versus YAML versus minified: the token cost of the same data in each format.

100% client-side⌗ exact o200k tokenizer⌁ zero uploads
5000

Sample payload (pretty json)

{
  "order_id": "ord_8f3k2m1",
  "status": "fulfilled",
  "customer": {
    "id": "cus_44a91",
    "name": "Dana Reyes",
    "email": "dana@example.com",
    "vip": true
  },
  "items": [
    {
      "sku": "FORG-PRO-1Y",
      "description": "FORG Pro annual license",
      "quantity": 3,
      "unit_price_usd": 180
    },
    {
      "sku": "FORG-ADDON-SSO",
      "description": "SSO add-on",
      "quantity": 1,
      "unit_price_usd": 49.5
    }
  ],
  "totals": {
    "subtotal_usd": 589.5,
    "tax_usd": 47.16,
    "total_usd": 636.66
  },
  "shipping": null,
  "notes": [
    "expedite provisioning",
    "PO required on invoice"
  ],
  "created_at": "2026-06-11T14:32:09Z"
}

A fixed representative payload — nested objects, arrays, strings and numbers — rendered in all three formats and tokenized identically.

Loading tokenizer… counts appear in a moment.

Pretty JSON191 tok · $72.68/mo
Minified JSON — cheapest141 tok · $53.65/mo
YAML144 tok · $54.79/mo

Verdict: Minified JSON wins on tokens. Indentation whitespace in pretty JSON tokenizes poorly; YAML drops braces and quotes but spends tokens on newlines and indentation. For machine-to-machine payloads, minify.

Exact o200k_base counts, tokenized in your browser. Monthly cost prices the payload as fresh input at GPT-5.4 rates, 30.44 days/month.

o200k
exact GPT tokenizer, in-browser
≈3.6
chars/token Claude estimate, documented
18
models in the cost dataset
0
network requests per keystroke

How it works

Every agent pipeline serializes data into prompts — tool results, retrieved records, API payloads — and the serialization format is a cost decision almost nobody makes deliberately. The same order record can be pretty JSON, minified JSON or YAML, carry identical information, and differ by hundreds of tokens. Multiply by thousands of calls per day and the formatting convention becomes a line item.

This tool makes the difference concrete. A fixed, realistically nested sample payload — objects, arrays, strings, numbers, a null — is rendered in all three formats and each rendering is tokenized with the exact o200k_base encoder, the one current OpenAI models use, running locally in your browser. The bars show token counts; the dollar figures price each format as input at your selected model and daily volume.

The usual result surprises people: minified JSON wins. Pretty-printing loses because indentation whitespace tokenizes — two spaces per nesting level per line adds up fast. YAML sits in between: it sheds JSON's braces and quote characters but pays for structure with newlines and indentation of its own. The exact gaps depend on nesting depth and key length, which is why we show real counts instead of folklore.

Assumptions worth stating: the payload is fixed so the comparison is apples-to-apples; costs price input tokens only, with no caching or batch discounts; and months are 30.44 days. The YAML emitter is a minimal one that handles plain data — the same subset you would actually ship between services.

The practical playbook: minify anything machine-generated before it enters a prompt, reserve pretty-printing for content the model must visually reason about (rare), and re-measure when your payload shape changes. To see what whitespace costs in your own prompts rather than our sample, the Token Counter takes arbitrary text, and the Prompt Compressor quantifies cleanup savings line by line.

Frequently asked questions

Why does pretty-printed JSON cost more tokens than minified JSON?

Indentation. Every level of nesting adds two or more spaces to every line, plus a newline, and those whitespace runs become real tokens. On a typically nested payload the pretty version runs 20-50% more tokens than the minified version of byte-identical data. The model gains nothing from the formatting — it parses both equally well.

Is YAML always cheaper than JSON?

No, and this tool shows the honest answer for a realistic payload. YAML drops braces, brackets and most quotes, which helps, but it pays for structure with newlines and indentation that JSON's minified form avoids entirely. For flat or shallow data YAML often beats pretty JSON yet loses to minified JSON. Measure your own shape before standardizing.

Does format choice affect model output quality?

Sometimes, and you should weigh it. Models have seen enormous amounts of JSON in training and follow JSON schemas reliably; YAML's significant whitespace gives models slightly more room to produce subtly invalid output. If you need structured output back, JSON with a schema is the safer ask — pay the token premium on input only by minifying what you send.

How is the monthly dollar figure calculated?

Each format's exact o200k token count is priced as fresh input at the selected model's verified per-million-token rate, multiplied by your payloads-per-day and our 30.44 days-per-month convention. Output tokens, caching and batching are excluded so the comparison isolates the one variable you control here: serialization format.

Are the token counts exact?

Yes for the GPT family: the page runs the real o200k_base encoding via js-tiktoken, entirely in your browser, on each rendered format. Claude's tokenizer is not public, so Claude-priced rows use the same o200k counts — relative format rankings hold across tokenizers even when absolute counts shift a few percent.

Built by FORG — AI cost observability for agentic coding. Free tools, no signup, nothing leaves your browser.

Learn about FORG