How to minify JSON without changing its values
JSON minification removes spaces, tabs, and line breaks that exist between tokens. It keeps whitespace inside quoted strings because that whitespace belongs to the data. A person’s name such as "Ada Lovelace" must retain its internal space.
- Paste a document or open a local file.
- Choose Minify JSON. Invalid syntax stops the operation and reports an error.
- Review warnings and the compact result. Copy the output or download
minified.json.
The status and output size help you check the result. The minification message reports bytes of whitespace removed from the input. If the input was already compact, zero bytes removed is a normal result.
Before and after JSON minification
Readable version:
{
"name": "Ada Lovelace",
"active": true,
"score": 98.50
}Compact version:
{"name":"Ada Lovelace","active":true,"score":98.50}The whitespace surrounding the fields disappears. The name’s internal space and the original number token 98.50 remain. Sorting is a separate option: leave Sort keys unchecked when you want to preserve member order.
Minification and compression solve different problems
A JSON minifier creates valid JSON text with fewer layout characters. Gzip or Brotli compress the bytes sent over a connection. Minified JSON stays directly readable by a JSON parser; compressed bytes must first be decompressed.
The benefit depends on the document. Indented files contain more removable whitespace than one-line payloads. A minifier does not reduce a long string, shrink an array’s items, remove unused properties, or replace repeated values. Removing those requires a deliberate data-model change.
When measuring a live API, look at the response’s actual transferred size and server compression settings. The tool reports UTF-8 text bytes, not a network benchmark or a simulated gzip result.
Why removing whitespace with a regular expression is risky
A blanket replacement such as text.replace(/\s/g, "") removes spaces and line breaks inside strings too. That can turn "New York" into a different value. This tool reads the JSON structure and writes the original tokens with layout whitespace removed.
That approach also keeps long integer IDs, escaped strings, duplicate object members, and exponential number notation visible. Any duplicate-key or number-range warning still matters to the application that will consume the result.
When compact JSON is useful
- Preparing a compact document to paste into a request body.
- Reducing the size of a JSON text file that includes extensive indentation.
- Inspecting whether an export contains removable layout whitespace.
- Keeping a machine-facing artifact compact while maintaining a readable source version.
For review and debugging, switch back to JSON Formatter & Validator. For structure inspection, use the JSON tree viewer. Each view serves a different stage of the same workflow.
Frequently asked questions
Does JSON minification remove spaces inside strings?
No. Spaces and escape sequences inside string tokens remain intact. Only whitespace between tokens is removed.
Does minification fix invalid JSON?
No. The tool validates first and stops on invalid syntax. Use Repair preview for the supported edits, or correct the reported error manually.
Will minifying JSON improve every API response?
The reduction depends on how much layout whitespace exists. Already compact JSON may not shrink. Network compression and the amount of data returned are separate considerations.
Can I restore the original layout?
Formatting creates a new readable layout but cannot recover the exact indentation or line-break style that was removed. Keep the source if that exact layout matters.
RELATED GUIDES
Understand the document you are working with.
Fix common JSON errors
Spot trailing commas, missing quotes, and invalid escapes with practical before-and-after examples.
Read the guide →LEARN BY DOINGJSON examples explained
Understand objects, arrays, nested API responses, and every JSON value type.
Read the guide →FOUNDATIONSJSON vs JavaScript objects
Know what changes when data becomes text, and what parse and stringify really do.
Read the guide →