How to use JSON Formatter
- 1Paste your JSON into the input box
- 2Choose 2 spaces or 4 spaces to indent, or Minify to strip all whitespace
- 3Read the formatted result, or the parser error if the JSON is not valid
- 4Fix any reported problem at the character position given
- 5Copy the result with the copy button
What JSON Formatter does
JSON has no opinion about whitespace. A document can arrive as a single unbroken line thousands of characters long, and it is exactly as valid as the same data indented across two hundred readable lines. Machines emit the compact form because it transfers faster; people need the indented form because nesting is impossible to follow otherwise.
Formatting is therefore a round trip: parse the text into real values, then serialise it back with indentation. That has a useful side effect — anything that cannot be parsed cannot be formatted, so the act of pretty-printing is also a validation. If you get indented output, the document is valid JSON. If you get an error, the message points at what broke.
When to use it
- Reading an API response
- Responses from a real service arrive minified. Indenting one before you read it is usually the fastest way to see which fields are actually present and how deeply the objects nest.
- Finding the syntax error
- A config file that a program refuses to load is nearly always one trailing comma or unquoted key. The parser message names the character position, which is quicker than reading the file line by line.
- Shrinking a payload
- Minify strips every space and newline. On a large document that is often a 15–20% size reduction before any compression, which matters for a config bundled into a page or an app.
- Comparing two documents
- Two JSON files that differ only in whitespace look completely different in a diff. Formatting both to the same indentation first makes the real differences the only ones left.
JSON Formatter settings explained
- 2 spaces
- The default, and the convention most JavaScript and web tooling emits. Keeps deeply nested documents from running off the right-hand edge while still making the structure obvious.
- 4 spaces
- More visually distinct nesting, common in Python and Java projects. Better for shallow documents you need to read carefully; wasteful once nesting passes four or five levels deep.
- Minify
- Removes all optional whitespace and puts the document on one line. The data is unchanged — key order and every value stay exactly as they were — only the formatting is dropped.
- Live validation
- Formatting parses the document first, so invalid JSON produces an error rather than output. The message comes straight from the browser's own parser and names the position where parsing stopped.
Common parser errors and what they mean
| Message | Usual cause | Fix |
|---|---|---|
| Unexpected token } / ] | A trailing comma after the last item | Delete the comma before the bracket |
| Unexpected token ' | Single quotes around a string or key | JSON requires double quotes |
| Unexpected end of JSON input | The document was truncated | A closing bracket or brace is missing |
| Unexpected non-whitespace character | Two documents pasted together | Keep only one top-level value |
Limits and what to expect
- Strict JSON only: no comments, no trailing commas, no single-quoted strings, no unquoted keys.
- Key order is preserved exactly as written — this tool never sorts or reorders anything.
- Numbers are parsed as JavaScript doubles, so integers beyond 2^53 lose precision on the round trip.
- Duplicate keys in the same object collapse to the last one, which is what every JSON parser does.
- Very large documents, past a few megabytes, may take a moment since the whole file is parsed at once.
Troubleshooting
- "Unexpected token }" but the JSON looks right
- There is almost certainly a comma after the final item in an object or array. JavaScript object literals allow that; JSON does not. Delete the comma immediately before the closing brace or bracket.
- My config file will not parse
- Many config formats that look like JSON are not: JSON5, JSONC and TypeScript config files permit comments and trailing commas. Strip the comments before formatting, or the parser will stop at the first slash.
- Large numbers changed value
- IDs beyond about 9 quadrillion exceed what a JavaScript number can hold exactly, so the round trip rounds them. If your data carries IDs that long, they should be quoted as strings in the source.
- Some keys disappeared
- The object contained the same key twice. Every JSON parser keeps only the last occurrence, so the duplicate is lost on parsing rather than on formatting — the source document was already ambiguous.
Your files and your privacy
The document is parsed and re-serialised by the browser's own JSON implementation, inside the page. Nothing is sent to a server, logged, or retained after you close the tab. This matters for JSON specifically: API responses and config files routinely carry access tokens, connection strings and customer records that should never be pasted into a hosted service.
What to use next
FAQ
Does formatting JSON change the data?
No. Parsing and re-serialising preserves every value and the order of keys; only whitespace changes. The two exceptions are inherent to JSON itself — duplicate keys in one object collapse to the last, and integers beyond 2^53 lose precision because they exceed what a double can represent exactly.
Why does my JSON say "Unexpected token"?
Nearly always a trailing comma after the last item, single quotes instead of double, or an unquoted key. All three are legal in a JavaScript object literal and illegal in JSON, which is why hand-written files trip on them so often. The error names the character position where parsing stopped.
Can this tool validate JSON as well as format it?
Yes, unavoidably. Formatting requires parsing, so valid input produces indented output and invalid input produces the parser's error message instead. If you only want a verdict without reformatting, the JSON validator gives one directly.
What is the difference between minifying and compressing?
Minifying removes whitespace from the text and leaves it readable by any JSON parser, typically saving 15–20%. Compression such as gzip re-encodes the bytes into a form that must be decompressed first, and saves far more. They stack: minify, then let the server compress.
Does it support comments or trailing commas?
No, because the JSON specification does not. Formats that allow them — JSON5, JSONC, and the tsconfig.json style — are supersets of JSON, and a strict parser stops at the first comment character. Remove them before formatting.
Is my JSON sent to a server?
No. The parsing runs in your browser using its built-in JSON support, with no network request at any point. The tool works offline, which is the simplest way to confirm nothing is being transmitted.