Input
Output
The formatted JSON appears here as you type.
Ctrl+Enter run / or Ctrl+K search tools Press Ctrl+D to bookmark this page
How to minify JSON
- Paste your JSON into the Input box, or drop a file onto it.
- The minified version appears in the Output box straight away, with the size before and after.
- Copy it, or download it as a
.min.jsonfile. Switch to Format to make it readable again.
What minifying removes, and what it keeps
Minifying removes the spaces, tabs and line breaks between items. That is all. Everything that carries meaning stays exactly as it was:
- spaces inside strings, such as
"New York"; - numbers, including very large IDs and forms like
1.0or1e5; - escape sequences such as
\u00e9; - the order of keys (unless you turn on Sort keys).
For example, this 54-byte object:
{
"id": 7,
"name": "Ada",
"tags": [ "a", "b" ]
} becomes 38 bytes:
{"id":7,"name":"Ada","tags":["a","b"]} When minifying helps, and when it does not
- Helps: embedding JSON in a URL, an environment variable or a single log line; storing many small documents; keeping test fixtures compact.
- Small gain: API responses sent with gzip or Brotli compression. Compression already removes most of the cost of whitespace, so the saving after compression is usually modest.
- Avoid: configuration files and anything people edit by hand. Keep those formatted and minify only the copy you ship.
Invalid JSON cannot be minified safely. If the input has mistakes, the Output box lists them, and Fix it can repair the common ones first.
Frequently asked questions
Does minifying change any values?
No. It only removes whitespace between items. Strings, numbers, escapes and key order stay exactly as they were.
How much smaller will my JSON get?
It depends on how it was indented. Typical pretty-printed JSON shrinks by 15 to 40 percent. The summary under the tool shows the exact size before and after.
Is minified JSON still valid JSON?
Yes. Whitespace between items is optional in JSON, so the minified text is valid and parses to exactly the same data.
How do I make minified JSON readable again?
Switch the tool to Format, or open the JSON Formatter. It adds indentation and line breaks without changing any values.
Minify JSON in your code
Each example prints a formatted version and then a minified one, the last line of the output.
Java
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
public class FormatJson {
public static void main(String[] args) throws Exception {
String text = "{\"name\":\"Ada\",\"langs\":[\"en\",\"fr\"],\"active\":true}";
ObjectMapper mapper = new ObjectMapper();
// Throws JsonProcessingException (with line and column) on invalid JSON.
JsonNode tree = mapper.readTree(text);
// Jackson's default pretty printer puts a space before the colon
// and keeps short arrays on one line.
System.out.println(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(tree));
System.out.println(mapper.writeValueAsString(tree)); // minified
}
} Uses Jackson (com.fasterxml.jackson.core:jackson-databind).
JavaScript
// Format (pretty-print) and minify JSON with the built-in JSON object.
// Note: JSON.parse turns integers above 2^53 into approximations.
const text = '{"name":"Ada","langs":["en","fr"],"active":true}';
const value = JSON.parse(text); // throws SyntaxError on invalid JSON
console.log(JSON.stringify(value, null, 2)); // 2-space indent
console.log(JSON.stringify(value)); // minified Python
import json
text = '{"name":"Ada","langs":["en","fr"],"active":true}'
# Raises json.JSONDecodeError (with .lineno and .colno) on invalid JSON.
value = json.loads(text)
print(json.dumps(value, indent=2, ensure_ascii=False)) # 2-space indent
print(json.dumps(value, separators=(",", ":"), ensure_ascii=False)) # minified Go
package main
import (
"bytes"
"encoding/json"
"fmt"
)
func main() {
text := []byte(`{"name":"Ada","langs":["en","fr"],"active":true}`)
// Indent and Compact work on the raw bytes, so numbers keep their exact text.
var pretty bytes.Buffer
if err := json.Indent(&pretty, text, "", " "); err != nil {
fmt.Println("invalid JSON:", err) // *json.SyntaxError has an Offset field
return
}
fmt.Println(pretty.String())
var compact bytes.Buffer
if err := json.Compact(&compact, text); err != nil {
fmt.Println("invalid JSON:", err)
return
}
fmt.Println(compact.String())
} Last verified . Each example is run automatically and its output checked.