Minify JSON
Paste JSON and get it back on one line, with every space between tokens removed. Prettify parses the document first, so the result is always valid JSON, and it tells you how many characters you saved. Numbers keep the digits you wrote. The minifier runs in your browser.
What minifying does
Minified JSON is the same data with no whitespace between tokens. A formatter adds line breaks and indentation so a person can read the document. A minifier removes them so a machine reads fewer bytes. Use it for a request body, a value in an environment variable, a cookie, or a file that is sent over the network many times.
Prettify does not minify the text with a search and replace. It parses the document into data and writes the data back on one line. That is why the result is always valid, and why spaces inside a string stay where they are.
Key features
The minifier keeps everything that is data and removes only what is layout.
- Numbers keep their exact digits. A 64-bit ID such as 9007199254740993 and a price such as 4.10 are written as you pasted them.
- Key order stays the same. The minifier does not sort keys.
- Spaces, tabs, and line breaks inside a string value stay, because they are part of the value.
- Comments and trailing commas are accepted in the input. They are not written to the output, and a note says so.
- The summary gives the length of the result and how many characters were removed.
- Download saves the result as prettify.min.json.
How to minify JSON
Minify in the box on this page, or in the editor for a larger document. The box takes documents up to 512 KB.
- Paste your JSON into the box labeled "Paste your JSON", or select "Try an example".
- Read the summary above the result. It shows the length of the minified JSON and how much shorter it is.
- Select Copy to put the result on the clipboard, or Download to save it.
- If the JSON does not parse, read the line and column in the error, then select "Fix it in the editor".
- In the editor, open the command palette with Cmd+K (Ctrl+K on Windows and Linux) and run Copy Minified or Download Minified at any time.
Worked example: a product record
The record below has an ID larger than JavaScript can hold exactly, a price with a trailing zero, and a string with two spaces in it. The second block is the result from the box.
The result is 100 characters, 22 fewer than the input. The ID and the price did not change. A minifier that converts through JavaScript numbers would write the ID as 9007199254740992 and the price as 4.1. The two spaces in the note are still there.
{
"id": 9007199254740993,
"name": "Desk lamp",
"price": 4.10,
"tags": ["home", "light"],
"note": "two spaces"
}
{"id":9007199254740993,"name":"Desk lamp","price":4.10,"tags":["home","light"],"note":"two spaces"}Minify and indent in the editor
The editor shows formatted JSON and copies minified JSON, so you do not need two tools. Settings has a JSON indent option, with 2 spaces, 4 spaces, or a tab. The Raw view, Copy Formatted, Download, and Save all use that indent. Copy Minified and Download Minified in the command palette ignore it and write one line.
The editor also handles large files. It parses big documents in the background, so a file of many megabytes stays responsive while you minify it.
Common uses
Minified JSON is the form most programs send and store. These are the usual reasons to make it by hand.
- Put a JSON value in an environment variable or a command-line argument, which must be one line.
- Paste a request body into curl or an HTTP client.
- Make a fixture or a config file smaller before you commit it.
- Compare the size of a payload before and after a change.
Frequently asked questions
Does minifying change my data?
No. Only whitespace between tokens is removed. Keys, values, key order, and the exact digits of every number stay the same, so a program reads the same data as before.
Is my JSON uploaded to minify it?
No. Prettify parses and minifies the JSON in your browser, so it never leaves your device. That makes the tool safe for API keys, tokens, and customer data.
How do I get the formatted JSON back?
Paste the minified JSON into the JSON Formatter, or open it in the editor. The editor indents it again with the indent you chose in Settings.
What if my JSON has an error?
The box shows the line and column of the error and does not minify. Select "Fix it in the editor", where common mistakes such as trailing commas and single quotes can be repaired.
How much smaller does JSON get?
It depends on the indentation and the length of the values. The example on this page gets 18 percent shorter. Compression such as gzip on the server saves more, and works on minified JSON too.
Is the minifier free?
Yes. Minifying on this page and with Copy Minified and Download Minified in the editor is free, with no account and no limit on use.