Trim the whitespace from every string in a JSON document

A minifier protects what is inside your quotes; this cleans it. Paste JSON and get every string value trimmed at any depth — including the non-breaking spaces a spreadsheet paste leaves behind — with numbers, booleans, nulls, key order and array positions untouched.

Try:
Cleaned JSON

About this tool

json-trim-strings walks a valid JSON document and rewrites the whitespace of every string value, at any depth, inside objects and arrays. Structure is never touched: numbers, booleans and nulls are copied through unchanged, key order is preserved, and arrays keep their length and their positions.

That makes it the opposite of a minifier. A minifier removes the whitespace between tokens and deliberately protects the inside of every quoted string. Here the structure is fine and the payload is dirty — " Berlin" and "Berlin" are different join keys, a padded " 42 " breaks a downstream cast, and a duplicate check quietly reports two customers where there is one.

The defaults are the safe ones: trim both ends, leave the inside of the string exactly as it was, treat the full Unicode whitespace set as blank, and copy object keys verbatim. Everything past that is opt-in.

Worked example

Input, with the defaults (trim both ends, keep the interior, indent 2):

{"name": "  Ada  ", "city": " Berlin ", "tags": [" x ", "y  "], "visits": 7}

Output:

{
  "name": "Ada",
  "city": "Berlin",
  "tags": [
    "x",
    "y"
  ],
  "visits": 7
}

visits stayed the number 7 — a trimmed string is still a string here, and nothing is retyped.

Choosing the options

Everything runs locally in WebAssembly in your browser. Nothing is uploaded, there is no account, and there is no daily quota.

Limits and edge cases

FAQ

How is this different from a JSON minifier?

They are opposites. A minifier strips the whitespace between tokens — the indentation and newlines that make a document readable — and protects everything inside the quotes. This tool leaves the structure alone and cleans the text inside the quotes. Set the indent to 0 if you also want the result minified.

My values look identical but still do not match. What is going on?

Almost always a non-breaking space. Spreadsheets and web pages are full of U+00A0, U+202F and U+3000, and they are invisible in every editor while being a different byte sequence from a plain space. The default unicode whitespace setting trims them; switch to ascii only if those characters are genuinely part of your data.

Will this change my numbers, booleans or nulls?

No. Only string values are rewritten. 7, true and null are copied through byte-for-byte, and a string is always still a string afterwards — " 42 " becomes "42", never 42. If you want real types back, run the result through json-coerce-types.

Can I protect one field, like an indented code block or a hash?

Yes. Put its key in Keys to never touch and its value is copied byte-for-byte, at any depth. The reverse also works: put a key in Only these keys to clean just that field and leave the rest of the document alone. Strings inside an array inherit the key their array is stored under, so naming tags reaches the items of "tags": [" x "].

What happens to a value that was only whitespace?

You choose. By default " " becomes "". Set Values left empty by the trim to null if a blank really means "missing", or to drop to remove the key from its object entirely. A value that was already "" before the trim is never affected by this setting, and inside an array drop writes null so positions do not shift.

Is my data uploaded anywhere?

No. The whole transform is a WebAssembly module running in your browser tab, so the document never leaves your machine. The same code ships in the gizza CLI if you would rather clean files from a terminal or a script.

Developer & Automation Access

Run it from the terminal

Same engine as this page, headless — via the gizza CLI:

gizza tool json-trim-strings '{"name": "  Ada  ", "city": " Berlin ", "tags": [" x ", "y  "]}'

New to the CLI? Get gizza →

Open it by URL

Pre-fill and auto-run this tool with query parameters — the names match the API/CLI:

https://gizza.ai/tools/json-trim-strings/?input=%7B%22name%22%3A%20%22%20%20Ada%20%20%22%2C%20%22city%22%3A%20%22%20Berlin%20%22%2C%20%22tags%22%3A%20%5B%22%20x%20%22%2C%20%22y%20%20%22%5D%7D&trim=both&internal=keep&whitespace=unicode&keys=true&empty=keep&only_keys=name%2Ccity&skip_keys=code%2Csignature%2Cpassword_hash&indent=2

Machine-readable descriptor: tool.json — title + parameters JSON Schema for agents.