JSON tool
JSON Minifier
Remove unnecessary JSON whitespace and compare original and minified sizes instantly.
Result
Your result will appear here.
How to use JSON Minifier
- Paste valid JSON.
- Select Minify and copy or download the compact result.
Example
{
"name": "sample",
"enabled": true
}Common use cases
- Shrinking a JSON object that you embed in an HTML page, a script, or a test fixture so the source file stays small.
- Preparing one-line JSON for a command-line argument or an environment variable, where line breaks cause quoting problems.
- Comparing a formatted and a minified copy of the same data to see how much of a file is whitespace.
Input and output examples
| Input | Output | Notes |
|---|---|---|
{
"name": "sample",
"enabled": true
} | {"name":"sample","enabled":true} | Whitespace removed; values unchanged. |
{"x":1.0,"y":1e3} | {"x":1,"y":1000} | Numbers are written in JavaScript’s normal form. |
Common mistakes to avoid
- Minified JSON is hard to diff and review. Keep the readable version in version control and minify only build output.
- Large integers change. 9007199254740993 becomes 9007199254740992 after a round trip through JavaScript numbers. Store such IDs as strings.
- Minifying does not compress. The reduction figure counts only removed characters, and a server that gzips the response will change the transferred size again.
Technical details
The input is parsed with JSON.parse and written with JSON.stringify without indentation, following ECMA-404 and RFC 8259. Whitespace outside strings is removed and whitespace inside strings is kept. Size is measured in JavaScript string length (UTF-16 code units), so an emoji counts as two characters.
Frequently asked questions
Does minifying change JSON values?
The removed whitespace does not change values. Two details can change: numbers are written in JavaScript’s normal form (1.0 becomes 1), and integers above 9007199254740991 lose precision.
Is whitespace inside strings removed?
No. Spaces inside a quoted string are part of its value and are kept.
What does “Reduced by” mean?
It is 1 minus the minified length divided by the original length, shown as a percentage. Both lengths are counted in characters.
Why is the saving smaller than gzip reports?
This tool only removes formatting whitespace. Gzip or Brotli compression on a server works on the bytes and usually shrinks JSON much more. This tool does not compress anything.
Can I minify JSON that contains comments?
No. The input must be valid JSON, and a comment causes a parse error. Remove the comments first.
Does the tool keep my original key order?
Yes. Keys are written in the order the parser read them, except that a duplicate key keeps only its last value.