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.
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
- Trim which end —
both(default),leading,trailing, ornoneto leave the edges alone and rewrite only the interior. - Whitespace inside the string —
keep(default) makes this a pure trim;collapseturns every inner run into a single space, so" Ada Lovelace "becomes"Ada Lovelace";removedeletes it, so" AB 12 CD "becomes"AB12CD"— useful for SKUs, IBANs and part numbers. - What counts as whitespace —
unicode(default) also catches the invisible characters that survive a spreadsheet or web copy-paste: non-breaking spaceU+00A0, narrow no-break spaceU+202F, ideographic spaceU+3000.asciilimits it to space, tab, newline, carriage return and form feed, so an NBSP stays part of the content. - Also trim object keys — off by default. When on, a key literally named
" first name "becomes"first name". - Values left empty by the trim — a value that was nothing but whitespace becomes
""(default),null, or is dropped from its object. - Only these keys / Keys to never touch — limit the pass to named fields, or protect fields whose padding is meaningful. Both match key names at any depth, and a key in both lists is skipped.
- Indent —
0minifies onto one line,2(default) through8pretty-print.
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
- The input must already be valid JSON. Comments, trailing commas and unquoted keys are rejected with the line and column of the problem — repair the document first.
- The input cap is 5 MB (5,000,000 bytes); the whole document is parsed into memory.
- Values are never retyped. A trimmed
" 42 "becomes the string"42", not the number42— usejson-coerce-typesfor that. - Zero-width characters (
U+200Bzero-width space,U+FEFFbyte-order mark) are content, not whitespace, under both whitespace settings —zero-width-cleanerremoves those. - With key trimming on, two keys in the same object that trim to the same name are an error, not a silent overwrite.
- Only these keys matches key names, so a bare top-level string document has no key and is left alone when the list is non-empty.
- Inside an array, a value emptied by the trim becomes
nullrather than disappearing, so indexes and array length never shift. - Indent values outside 0–8 are clamped rather than rejected.
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=2Machine-readable descriptor: tool.json — title + parameters JSON Schema for agents.
