JSON Formatter: Minify & Beautify JSON Online Free
Free online JSON formatter. Minify JSON to shrink file size, or beautify JSON with 2-space indentation for readability. Validates syntax in your browser.
JSON Formatter
Documentation
JSON Formatter: Minify and Beautify JSON
A JSON formatter is a tool that rewrites JSON text in a different layout without changing the data inside it. This JSON formatter does two things: it minifies JSON by stripping extra whitespace, and it beautifies JSON by adding indentation and line breaks so people can read it.
What is JSON?
JSON, short for JavaScript Object Notation, is a text format for storing and sending data. Web servers use it to send information to apps and browsers. Programs use it for settings files. It stores data as objects, written with curly braces {}, and arrays, written with square brackets []. Inside an object, each piece of data has a name, called a key, and a value. A value can be a string, a number, true, false, null, or another object or array.
A small JSON object looks like this:
1{
2 "name": "John Doe",
3 "age": 30,
4 "isEmployee": true
5}
6How this JSON formatter works
Some JSON tools read the text into a programming language's own data structure and then write that structure back out as text. That round trip can change the data. It can rewrite very large numbers, drop numbers that are too big to represent, and reorder the keys in an object.
This tool avoids that. It reads the input character by character and checks that it follows the JSON grammar. When it rewrites the output, it copies each number and each string exactly as it was typed, in the same order. Minifying or beautifying a document never changes a number, a key, the order of keys, or a duplicate key.
If the text is not valid JSON, the tool stops and shows an error instead of guessing what was meant.
The formatting happens in the browser. The tool does not send the pasted text to a server. The input is added to the page's web address as a query parameter, so a formatted document can be shared or bookmarked with a link.
How to minify JSON
- Paste JSON into the input box.
- Click "Minify."
- The tool removes spaces, tabs, and line breaks between tokens and shows the result below.
- Click "Copy to clipboard" to copy the result.
Example
Before:
1{
2 "name": "John Smith",
3 "age": 32,
4 "skills": [
5 "JavaScript",
6 "HTML",
7 "CSS"
8 ]
9}
10After:
1{"name":"John Smith","age":32,"skills":["JavaScript","HTML","CSS"]}
2JSON minification formula
The space saved by minifying can be written as:
For the example above, the formatted version is 98 bytes and the minified version is 67 bytes:
The exact savings depend on how much whitespace and indentation the original document had. A document with deep nesting and 4-space indentation shrinks more than a document that was already compact.
How to beautify JSON
- Paste JSON into the input box. It can already be minified or messily formatted.
- Click "Beautify."
- The tool adds 2-space indentation, one line break per key or array item, and a space after each colon.
- Click "Copy to clipboard" to copy the result.
Example
Before:
1{"name":"John Smith","age":32,"skills":["JavaScript","HTML","CSS"]}
2After:
1{
2 "name": "John Smith",
3 "age": 32,
4 "skills": [
5 "JavaScript",
6 "HTML",
7 "CSS"
8 ]
9}
10An empty object or array stays on one line, as {} or [], instead of being split across three lines.
Common JSON errors this tool catches
JSON has a strict grammar, stricter than a typical programming language. This tool rejects text that breaks any of these rules and reports where in the text the problem starts:
- A missing comma between two values.
- A trailing comma after the last item in an object or array (not allowed in JSON, unlike in JavaScript).
- A key that is not wrapped in double quotes.
- Single quotes around a string instead of double quotes.
- Mismatched or missing brackets and braces.
- An invalid or incomplete escape sequence inside a string, such as a lone backslash.
JSON also has no syntax for comments. Text starting with // or /* is not part of the JSON grammar, so pasting JSON that contains comments produces an "Invalid JSON" error rather than JSON with the comments quietly removed. To format such a file, remove the comments first.
JSON formatter use cases
- Web development: reading API responses during debugging, and minifying configuration files before deployment.
- API development: checking that a request or response body is well-formed JSON.
- Data analysis: turning a compact JSON export into a readable layout for inspection.
- Configuration files: beautifying a config file before editing it by hand, then minifying it again afterward.
Alternatives
Code editors such as Visual Studio Code can format JSON files without leaving the editor. Command-line tools such as jq can format and filter JSON as part of a script. Programming languages ship JSON libraries too, such as Python's json module or JavaScript's built-in JSON object, which most programs use to parse JSON into their own data structures. An online formatter like this one is useful when a quick, one-off check is needed without installing anything.
History of JSON
Douglas Crockford specified JSON in the early 2000s, based on the way JavaScript writes object literals, but designed to be read and written by any programming language. The format was first documented publicly around 2001 and later standardized as RFC 4627 in 2006, then as RFC 8259 and ECMA-404 in 2013 and 2017. As web APIs grew through the 2000s, JSON replaced XML as the most common format for sending data between servers and browsers, mainly because it is shorter and maps directly onto data structures already built into JavaScript. Formatting and validation tools followed as JSON documents grew larger and more nested.
Frequently asked questions
Does minifying remove comments from JSON?
No. JSON has no comment syntax, and this tool does not add one. If the input contains // or /* style comments, the tool reports an "Invalid JSON" error instead of formatting it. Remove comments before pasting the text in.
Does formatting change my numbers or the order of my keys? No. The tool copies each number and string exactly as written and keeps keys in their original order, including duplicate keys, if any are present.
What indentation does the beautifier use? Two spaces per nesting level, with a space after each colon.
Is my JSON data sent to a server? No. Formatting runs in the browser. The text is added to the page's URL so the formatted result can be shared or bookmarked, but it is not uploaded anywhere.
Is there a size limit? There is no fixed limit, but the whole document is held in memory while it is parsed, so a very large file (many megabytes) may be slow on an older device.
Will invalid JSON just get partially fixed? No. If the input breaks the JSON grammar anywhere, the tool shows an error instead of returning a partial or guessed result.
References
- "Introducing JSON." JSON.org, https://www.json.org/json-en.html.
- Bray, T., ed. "The JavaScript Object Notation (JSON) Data Interchange Format." RFC 8259, IETF, December 2017, https://www.rfc-editor.org/rfc/rfc8259.
- "ECMA-404: The JSON Data Interchange Syntax." Ecma International, https://www.ecma-international.org/publications-and-standards/standards/ecma-404/.
- "JSON." MDN Web Docs, Mozilla, https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON.