JSON prompt token minifier
When you pass JSON into a prompt, every space, newline and indent is a billable token — on every call. This tool re-serializes your JSON at the minification level you choose and shows exactly how many tokens you save, so you can shrink large payloads without changing a single value.
How it works
The minifier parses your JSON (rejecting invalid input) and rebuilds it:
- Whitespace-only — removes all indentation and line breaks. Lossless and reversible; safe in every case.
- Key abbreviation — replaces long, repeated keys with short aliases and emits a one-line legend you paste once. Big wins on arrays of records.
- Full compact — whitespace stripping plus key abbreviation for the smallest possible payload.
Token counts use the standard ≈ 4-characters-per-token heuristic that closely tracks GPT and Claude tokenizers, so the before/after delta is a reliable guide to real savings.
Why whitespace costs more than you think
A developer-formatted JSON object like this:
{
"product_name": "Widget",
"unit_price": 9.99,
"in_stock": true
}
contains spaces, newlines and indentation that exist purely for human readability. The minified version:
{"product_name":"Widget","unit_price":9.99,"in_stock":true}
is semantically identical — every model that reads JSON can parse both forms equally. The only difference is the token count. For a small single object the saving is modest, but for an array of hundreds of records the savings compound: every removed space and newline across every record reduces the total.
When key abbreviation pays off
Key abbreviation is most effective when you have an array of many records that all share the same keys. For example, a table of 300 product records where each record has product_name, unit_price, category, and in_stock repeats those key names 300 times. Replacing them with n, p, c, and s saves the key characters on every single row. The legend n=product_name, p=unit_price, c=category, s=in_stock is paid once.
The trade-off is that the model must read the legend to interpret values correctly. For cases where the model needs to reason about the meaning of the data (classification, summarisation), keep readable keys. For cases where the model is just passing values through (extraction, formatting), short keys are fine.
Tips for prompt JSON
- Always strip whitespace. Pretty-printing is for humans; the model does not need indentation to parse JSON.
- Abbreviate only bulk data. For a 500-row table, short keys repeated 500 times save far more than the one-time legend costs.
- Keep a legend in the system prompt. One line like
t=title, p=pricepreserves meaning while keys stay tiny. - Re-check after edits. Adding fields can quietly re-inflate the payload — re-run before you ship a new version of the prompt.
- Consider context-caching too. If your JSON is a large static dataset, many APIs (including Anthropic’s and OpenAI’s) offer prompt/context caching so repeated tokens cost less on subsequent calls. Minifying plus caching together can reduce ongoing costs substantially.