# JSON minifying: what is removed, what is rewritten, how much you save

> How the minifier re-serialises JSON with no whitespace, which characters and numbers are rewritten along the way, realistic size savings, and the cases where minifying is not byte-for-byte safe.

- Tool: [JSON Minifier](https://toolsg.com/en/json-minify)
- Language: en (available: en, zh, ms, ta)
- Last verified against official sources: 2026-10-19
- Source site: ToolSG — a planning guide, not official or financial advice. Cite the agencies listed under Sources.

## Key figures at a glance

| Fact | Value | Source |
| --- | --- | --- |
| Method | JSON.parse then JSON.stringify with no indent — A rewrite of the value, not a regex that strips spaces. |  |
| When it runs | On every keystroke or paste — There is no Minify button; the output box updates as you type. |  |
| Typical saving | About 42% from 2-space JSON, about 55% from 4-space JSON — Measured on the 100-record example below; heavily nested data saves more, dense arrays of numbers less. |  |
| Whitespace inside strings | Kept exactly — Only whitespace between tokens is removed. |  |

## What the tool does

Paste JSON and the right-hand box immediately shows a one-line version. Internally the page runs `JSON.parse` on the input and `JSON.stringify` on the result with no indent argument. If the text is not valid JSON, the output stays empty and the error appears in red; nothing is guessed or repaired. Empty input clears everything. The Copy button copies the output (the label changes to "Copied" for a moment); this page has no download button.

RFC 8259 allows insignificant whitespace (space, tab, line feed, carriage return) around the six structural characters and values. Removing it never changes the data model, which is why minified and pretty JSON are interchangeable for parsers.

## Worked example

Input (186 UTF-8 bytes):

```json
{
    "name": "Mei Tan",
    "city": "Singapore",
    "scores": [
        90,
        85.50,
        1e2
    ],
    "note": "a  b\/c é 中",
    "active": true,
    "spouse": null
}
```

Output (111 bytes, 75 saved, 40.3%):

```json
{"name":"Mei Tan","city":"Singapore","scores":[90,85.5,100],"note":"a  b/c é 中","active":true,"spouse":null}
```

Notice what else changed: `85.50` became `85.5`, `1e2` became `100`, `\/` became `/` and `é` became `é`. The two spaces inside `"a  b"` were kept.

## How much you save

Savings depend on indentation and nesting. For an array of 100 small records (`id`, `name`, `city`, a two-item `tags` array, `active`):

| Source layout | Bytes | Minified bytes | Saved |
| --- | --- | --- | --- |
| 2-space indent | 13,236 | 7,735 | 41.6% |
| 4-space indent | 17,236 | 7,735 | 55.1% |

After gzip, which most web servers apply, the gap shrinks sharply: 664 bytes for the 2-space version against 597 for the minified one, because repetitive whitespace compresses well. Minify for storage and logs; do not expect large transfer savings if the response is already compressed.

## Cases where minifying is not byte-identical

- **Numbers** are re-printed through JavaScript doubles. `12345678901234567890` becomes `12345678901234567000`, and `1e400` becomes `null`.
- **Duplicate keys** collapse to the last one, and integer-like keys such as `"2"` move ahead of other keys.
- **Escapes are decoded**: `</script>` comes out as the literal text `</script>`. If you embed minified JSON inside an HTML `<script>` block, that literal sequence can end the block early, so escape `<` again in your build step.
- **Line separators**: U+2028 and U+2029 are written as raw characters, which ES2019 and later accept inside strings.
- **Not JSON** means not minified: comments, trailing commas and single quotes make parsing fail. This is a JSON minifier, not a JavaScript one.

> **Tip:** If a downstream system signs or hashes the exact bytes of the document, minify once, store that result, and sign the stored copy. Minifying again later with another tool may reorder keys or normalise numbers differently.

## Common mistakes

- Expecting the text inside strings to be compacted: `"a  b"` keeps both spaces, and `\n` inside a string stays an escape.
- Minifying a document with 19-digit IDs and discovering the last digits changed.
- Assuming a minified file is encrypted or obscured; it is the same data and reformats instantly.
- Looking for a Download button; copy the result instead, or use the [JSON formatter](https://toolsg.com/en/json-formatter) page which can download.

## Related tools

Pretty-print again with the [JSON formatter](https://toolsg.com/en/json-formatter), check syntax with the [JSON validator](https://toolsg.com/en/json-validator), browse the structure in the [JSON viewer](https://toolsg.com/en/json-viewer), or convert records with [JSON to CSV](https://toolsg.com/en/json-to-csv). For plain text, the [text minifier](https://toolsg.com/en/text-minifier) removes whitespace without parsing.

## Frequently asked questions

**How much smaller does minifying make JSON?**

It removes only the whitespace between tokens, so the saving depends on how heavily the file was indented. The data itself does not change.

**Is my JSON sent to a server?**

No. Everything happens in your browser. Nothing you paste is uploaded, logged or stored, which matters when the document contains keys, tokens or personal data.

**Why is my JSON reported as invalid?**

The most common causes are trailing commas, single quotes instead of double quotes around keys and strings, and unescaped line breaks inside a string. The error message gives the line and column of the first problem.

**Does it change my data?**

No. The document is parsed and re-serialised, so only whitespace changes. Key order is preserved and values are untouched.

**Can it handle large documents?**

Yes, within your browser's memory. Documents of a few megabytes are fine; extremely large files may make the page pause briefly while it parses.


## Sources

- [IETF — RFC 8259, The JSON Data Interchange Format](https://www.rfc-editor.org/rfc/rfc8259.html) — Insignificant whitespace, string escapes and number interoperability.
- [MDN — JSON.stringify()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
