User Guide
Paste your JSON
Drop it into the input box, however badly formatted. Minified, wrapped, copied out of a log — it does not matter. Load Sample shows the expected shape if you want a reference.
Press Validate first when something is wrong
Validation reports the specific parse failure rather than a generic complaint, which is what tells you where to look.
Format to read it
Prettify re-indents with two spaces per level, the convention most editors and style guides use. This is what turns an unreadable API response into something you can scan.
Minify to ship it
Minify strips every space and line break. Formatting is for humans; minified is what should go over the wire, and on a large payload the saving is significant.
Read the error message literally
“Unexpected token” means a character appeared where the grammar did not allow it — nearly always a trailing comma, a single quote, or an unquoted key. The section below lists the five that account for most failures.
Copy the result
Copy Output takes the whole thing. Note that formatting does not change the data at all — parsed and re-serialised JSON is semantically identical to what you pasted.
About the JSON Formatter and Validator
This tool does three separate jobs: it checks whether text is valid JSON, it re-indents it so a person can read it, and it strips it back down so a network does not have to carry the whitespace. All three run in your browser.
What JSON actually permits
JSON is defined by RFC 8259 and the grammar is deliberately tiny — the whole thing fits on one page at json.org grammar. Six value types exist: object, array, string, number, boolean and null. That is all.
Most validation failures come from assuming JSON allows something JavaScript allows. It does not. JSON is not a subset of JavaScript syntax in the way people expect, and the differences are exactly where files break:
| Mistake | Invalid | Valid |
|---|---|---|
| Trailing comma | {"a":1,} |
{"a":1} |
| Single quotes | {'a':1} |
{"a":1} |
| Unquoted key | {a:1} |
{"a":1} |
| Comment | {"a":1} // note |
Remove it entirely |
| Undefined / NaN | {"a":NaN} |
{"a":null} |
Two of these deserve emphasis. Trailing commas are legal in modern JavaScript and illegal in JSON, which is why hand-edited config files break so often. Comments are not permitted at all — a deliberate design decision, and the reason formats like JSON5 and JSONC exist.
Formatting versus minifying
Both operations parse the JSON and write it back out. Neither changes the data — the result is semantically identical, just spaced differently.
| Prettify | Minify | |
|---|---|---|
| Indentation | 2 spaces per level | None |
| Line breaks | One value per line | None |
| Relative size | Larger | Smallest possible |
| Use for | Reading, debugging, committing to a repo | API responses, storage, transmission |
On a large payload the difference is real. Whitespace can account for a third of a deeply nested document, and it is pure overhead once the file leaves human hands. Prettify while you work on it; minify what you ship. If you also need to compress JavaScript or CSS, the Code Minifier covers those.
Reading the error
“Unexpected token” means the parser met a character the grammar does not allow at that position. “Unexpected end of input” almost always means a closing brace or bracket is missing — count them. “Unexpected non-whitespace character after JSON” means the document ended and something followed it, typically two objects pasted one after another without an enclosing array.
A practical technique for large files: if the error position is unhelpful, cut the document in half and validate each half. Two or three rounds of that isolates the problem faster than reading line by line.
Privacy, and why it matters here
Everything runs in JavaScript inside this page. Nothing you paste is transmitted, logged or stored — which is the reason it is safe to use on data you would not paste into a random website. JSON pasted into a formatter is routinely an API response containing customer records, tokens or internal identifiers. Running the parse locally means that data never leaves the machine — which is the difference between a convenient tool and a disclosure incident.
Frequently Asked Questions
Why is my JSON invalid when it looks fine?
Almost always one of five things: a trailing comma, single quotes instead of double, an unquoted key, a comment, or a JavaScript value such as NaN or undefined. All are legal in JavaScript and none are legal in JSON.
Can JSON contain comments?
No. The specification excludes them deliberately, which is why hand-maintained config files so often fail to parse. If you need comments, use JSON5 or JSONC and strip them before parsing, or add a “_comment” key as a normal string value.
Does formatting change my data?
No. The tool parses the JSON and writes it back out, so the result is semantically identical — only the whitespace differs. A program reading it cannot tell the difference.
What does “Unexpected token” actually mean?
A character appeared where the grammar does not allow one. In practice it means look at the position given and just before it — usually a stray comma, a wrong quote character, or a missing brace.
Should I minify JSON before sending it?
Yes, for anything going over a network or into storage. Whitespace can be a third of a deeply nested document and serves no purpose once it leaves human hands. Keep the formatted version for reading and version control.
Why are trailing commas rejected?
Because RFC 8259 does not permit them, even though modern JavaScript does. This mismatch is the single most common cause of invalid JSON in hand-edited files.
Is my JSON uploaded for validation?
No. Parsing and formatting happen in JavaScript inside this page. That matters more than usual here, because JSON pasted into a formatter is frequently an API response containing real customer data or tokens.
How do I find the error in a very large file?
Cut the document in half and validate each half, then repeat on whichever half fails. Two or three rounds narrows it down far faster than reading through line by line.