Minify and validate JSON locally
Pretty-printed JSON is easy to read but wastes bytes in API payloads, config files and storage. This tool strips every bit of insignificant whitespace to produce a single compact line, and because it parses the input first you get validation in the same step — invalid JSON shows the exact parser error instead of silently producing broken output.
How it works
The minifier runs JSON.parse on your input to build the data structure, then
JSON.stringify with no indentation argument to serialise it back as compactly
as possible. Because it works on the parsed data rather than the raw text:
- spaces and newlines inside string values are preserved;
- only insignificant whitespace between tokens is removed;
- anything that is not valid JSON is rejected with the parser’s error message.
After minifying, the tool reports the new character count and how much you saved.
Example
This pretty-printed input:
{
"name": "api",
"tags": [ "a", "b" ]
}
minifies to:
{"name":"api","tags":["a","b"]}
The data is identical; only the indentation and spacing between tokens are gone. It runs entirely in your browser, so sensitive data is never uploaded.
Practical situations where minification matters
API payloads over slow or metered connections. Pretty-printed JSON from a REST API can be three to five times larger than its minified equivalent, because every level of nesting adds two spaces per character of indentation. On mobile networks or in serverless functions billed by data transfer, minification reduces cost.
Configuration values in environment variables. Some platforms accept a whole JSON object as a single environment variable — for example, a service account credentials file. Environment variables typically cannot contain newlines in all shells, so minifying to a single line is the only practical option.
Embedding JSON inside another format. When a JSON value must live inside a YAML string, an HTML attribute, or a shell script, the single-line form is far easier to quote and escape correctly.
Quick validation. If you are not sure whether some JSON is valid, pasting it here is faster than setting up a validator. The minifier rejects invalid input with the exact parser error rather than producing broken output.
Why minifying by deleting spaces is risky
A naive find-and-replace for spaces or newlines can corrupt string values that happen to contain those characters. For example, deleting all spaces from:
{"message": "hello world", "count": 10}
would produce {"message":"helloworld","count":10} — a different string value. This minifier parses the JSON first and re-serialises it, so spaces inside strings are always preserved.
Number precision note
JSON numbers are passed through the native JavaScript engine’s JSON.parse and JSON.stringify. Very large integers — those with more digits than a 64-bit double-precision float can represent exactly — can lose precision in this round-trip, just as they would in any standard JSON parser. If you are working with large integer IDs (for example, Twitter/X snowflake IDs), they are typically stored as strings in JSON for precisely this reason.