JSON Formatter
Free JSON formatter, beautifier and validator. Pretty-print JSON with 2-space indentation or minify it instantly in your browser. Nothing is uploaded.
Updated 2026-06-09 · Free · No sign-up · Runs privately in your browser
What is a JSON Formatter?
A JSON formatter takes a raw JSON string and re-prints it so it is either easy to read or as small as possible, while confirming it is valid. This tool does both jobs. Paste JSON into the box, then choose Format to pretty-print it with clean 2-space indentation, or Minify to collapse it into the smallest valid string. Because it parses your input first, it doubles as a JSON validator: if the text is not valid JSON, you get the exact reason instead of a broken result.
What does this tool do?
It performs two transformations on valid JSON. Format (also called beautify or pretty-print) adds line breaks and 2-space indentation so nested objects and arrays line up and the structure is obvious at a glance. Minify does the opposite: it removes every space, tab and newline that is not inside a string, leaving the most compact form for storage or network transfer. Either way the data itself is untouched — only whitespace changes. If the input cannot be parsed, the tool shows the parser’s error message so you know what to fix.
How does it work?
The method is a parse-then-serialize round trip, with no custom JSON engine of its own:
- The input string is read by the browser’s built-in
JSON.parse, which turns the text into an in-memory value (objects, arrays, strings, numbers, booleans, and null). - That value is written back out with
JSON.stringify. For Format it serializes with a 2-space indent, putting each key and array element on its own indented line. For Minify it serializes with no indent, so there is no whitespace between tokens.
Because JSON.parse runs first, any syntax problem stops the process and surfaces the parser’s own message — that is what makes the tool a validator as well as a formatter. The terms are simple: a token is a structural piece such as a brace, a key, or a value; whitespace is spaces, tabs and newlines between tokens; indentation is the leading spaces that show nesting depth, fixed here at two spaces per level. Everything runs locally, so nothing is uploaded.
Examples
Here are worked examples you can reproduce exactly in the tool. They all use the same starting JSON so you can see both directions.
Example 1: Format {"a":1,"b":[2,3]}. Clicking Format pretty-prints it with 2-space indentation:
{
"a": 1,
"b": [
2,
3
]
}
Each key sits one level (two spaces) in, and the array elements 2 and 3 each get their own line two levels deep.
Example 2: Minify the formatted block back down. Paste the indented version above (or the original) and click Minify. All non-string whitespace is removed and you get:
{"a":1,"b":[2,3]}
Minify and Format are inverses for whitespace: minifying a formatted string and formatting a minified one both return to the same data.
Example 3: An invalid input shows an error. Paste {"a":1,"b":[2,3],} — note the trailing comma after the array. The parser cannot accept it, so instead of output you see an Invalid JSON error carrying the parser’s own message. A missing quote, such as {a:1} where the key a is not quoted, fails the same way. Fix the flagged spot and the tool formats or minifies normally.
Format versus Minify at a glance
This table summarizes how the two actions differ on the same valid input. Sizes are illustrative for the small object above; the point is the direction of change, not exact byte counts.
| Aspect | Format (Beautify) | Minify |
|---|---|---|
| Indentation | 2 spaces per nesting level | none |
| Line breaks | one token group per line | none (single line) |
| Output size | larger (added whitespace) | smallest valid form |
| Best for | reading, reviewing, debugging | storage, transfer, embedding |
| Data changed? | no, whitespace only | no, whitespace only |
| Needs valid JSON? | yes (parsed first) | yes (parsed first) |
Common uses
A JSON formatter is a daily tool for anyone who touches structured data:
- Developers beautify a compact API response to read it during debugging, then minify config or payloads before shipping them.
- API testers paste responses from a request client to confirm the shape is correct and that the body is actually valid JSON.
- Data and config work — formatting a dense
package.json, settings file, or export makes diffs and manual edits far easier to follow. - Students and learners use the indentation to see exactly how objects nest inside arrays and how keys map to values.
If you are moving data between text-only systems alongside this, the base64 encode and decode tool covers binary-safe transport.
Tips and common mistakes
Most JSON errors come from a few predictable habits:
- No trailing commas. JSON does not allow a comma after the last element or property, unlike JavaScript object literals.
[2,3,]is invalid. - Keys must use double quotes.
{a:1}and{'a':1}both fail; only{"a":1}is valid JSON. - Comments are not allowed. Strip
//and/* */comments before formatting, or the parse fails. - Format for humans, minify for machines. Read with Format; store, cache, or send over the wire with Minify to save bytes.
- Numbers stay as numbers. Formatting never quotes a number, so
1stays1, not"1"; if you need a string, quote it in the source.
Limitations and notes
This tool formats and validates standard JSON only — it does not accept JSON5, JSONC, or comments, and it will not auto-repair a trailing comma or an unquoted key; it reports the error instead. Output uses a fixed 2-space indent, which matches the most common style for web and config files. Key order is preserved as the parser returns it, and very large inputs are limited only by your browser’s memory. Most importantly, parsing, formatting and minifying happen entirely in your browser with JavaScript, so your JSON is never uploaded, logged, or stored, making it safe for sensitive payloads and offline use once the page has loaded.
For related developer utilities, try the UUID generator, the hex to rgb converter, or the URL encoder and decoder, and browse the full Dev & Tech tools collection.
Frequently asked questions
How do I format JSON online?+
Paste your JSON into the input box, click Format, and the tool re-prints it with 2-space indentation so the structure is easy to read.
What does {"a":1,"b":[2,3]} look like when formatted?+
It becomes a multi-line block with each key indented two spaces, and the array 2 and 3 listed on their own indented lines inside square brackets.
What is the difference between Format and Minify?+
Format pretty-prints with 2-space indentation for reading; Minify strips all extra whitespace to the smallest valid string for storage or transfer.
Does this tool validate my JSON?+
Yes. It parses with JSON.parse first, so any syntax error shows the parser's exact message instead of producing broken output.
Why does my JSON show an Invalid JSON error?+
A trailing comma, a missing quote around a key, single quotes, or an unclosed bracket all break the parser; fix the flagged spot and try again.
Can I minify {"a":1,"b":[2,3]} that is already compact?+
Yes, and the output stays {"a":1,"b":[2,3]} because there is no extra whitespace to remove; minifying is safe to run repeatedly.
Is my JSON uploaded to a server?+
No. Parsing, formatting and minifying all run in your browser with JavaScript, so your data never leaves your device and nothing is stored.
Does formatting change my data or reorder keys?+
No. It only changes whitespace. Key order, values, numbers and nesting are preserved exactly as JSON.parse and re-serialization return them.