LLM Token Optimizer for JSON and XML

Make structured data cheaper to send to a model, without losing what it needs.

API responses and XML exports are full of things a language model does not need: null fields, empty arrays, pagination metadata, attribute prefixes and the same value repeated on every row. Each one costs tokens. This optimizer removes them and then writes the result in whichever format tokenises smallest: TOON, YAML, CSV or minified JSON.

The default clean-up only removes empty values and markup, so the data the model reads is unchanged. Rounding decimals and shortening long strings are lossy, so they are off until you turn them on. Token counts use the o200k_base encoding and everything runs in your browser.

How to use it

  1. Paste JSON or XML, or drop a file onto the editor.
  2. Review the optimized output on the right. It shows the token count before and after, and what was removed.
  3. Toggle the options or pin a format, then Copy the result into your prompt.

Questions

Does optimizing change my data?

The default options only drop null, empty-string, empty-array and empty-object fields, and for XML, the attribute prefixes and text markers the parser adds. Rounding numbers and shortening strings do change values, which is why they are off by default.

What does "factor out repeated fields" do?

When every row of an array has the same value for a field, such as a currency or region, that field is written once under "common" and removed from each row. The model still sees it, but it is paid for once instead of on every row.

Why does the cheapest format change between documents?

TOON and CSV win on arrays of uniform records. YAML or minified JSON are often smaller for deeply nested or irregular data. The optimizer counts each one and picks the lowest, or you can pin a format.

Will the model understand TOON?

Current models read TOON well because it looks like YAML with a CSV-style table for arrays. If a model struggles, pin YAML or JSON instead; the clean-up savings still apply.

All tools