The quick answer
The API response is one unreadable line, or your code stopped with a message like Unexpected token } in JSON at position 412 (older wording, newer browsers and Node phrase it differently) and you cannot tell what sits at position 412. Paste the text into the JSON formatter. Valid JSON comes back indented. Invalid JSON gets the line, the column and a likely cause.
- Paste the JSON into the left box, or drop a
.jsonfile on it. The result updates as you type. - Choose Format, then an indent of 2 spaces, 4 spaces or tabs.
- If the JSON is invalid, an error message gives the line, the column, the faulty line and a likely cause. Go to line jumps straight to it.
- Fix that one problem and the result updates. Then copy it or download it.
The seven reasons JSON is invalid
JSON grew out of JavaScript object syntax but kept only a small part of it. Many "invalid JSON" errors are one of these seven, and each fix is a character or two.
| What went wrong | Invalid | Valid |
|---|---|---|
| Trailing comma | {"a": 1, "b": 2,} | {"a": 1, "b": 2} |
| Single quotes | {'name': 'Ann'} | {"name": "Ann"} |
| Unquoted key | {name: "Ann"} | {"name": "Ann"} |
| Comment | {"a": 1, /* count */ "b": 2} | {"a": 1, "b": 2} |
| Quote or line break inside a string | {"say": "She said "hi""} | {"say": "She said \"hi\""} |
| NaN, undefined, True or None | {"n": NaN, "ok": True} | {"n": null, "ok": true} |
| Curly quotes or a hidden character | {“a”: 1} | {"a": 1} |
- Trailing commas and comments are fine in JavaScript and in files such as
tsconfig.json(a relaxed form called JSONC), but not in JSON. If your file is meant to allow them, turn on Allow comments and trailing commas. Comments are dropped from the result. - Single quotes and bare keys are what you get when you copy a printed Python dictionary or a JavaScript object literal. JSON has only lowercase
true,falseandnull, so Python'sTrue,FalseandNonefail too. - A string cannot hold a raw quote, line break or tab. Write
\",\nand\t. A Windows path such asC:\Users\annfails at\U. Worse,C:\tempis valid and quietly decodes asC:, a tab andemp. - NaN, Infinity and undefined are not JSON values. They usually come from a serializer: Python's
json.dumpswritesNaNby default, while JavaScript'sJSON.stringifywritesnullfor it. Usenullor leave the key out. - Curly quotes, non-breaking spaces and a byte order mark look fine on screen and arrive when you copy from a document, a chat app or a web page. The checker names the curly quotes and the lookalike space. A byte order mark at the very start is removed, with a note.
- Also common: a missing comma between items (look at the end of the previous line) and leading zeros such as
007, which need quotes if they are IDs.
How the tool shows where the problem is
A parser's own message often gives only a character position. The formatter reports the line and column, shows the faulty line and says what is likely wrong. It shows only the first problem, because later ones are often side effects of it.
- "This looks like HTML or XML, not JSON" means the first character was
<. An API sent back a web page or an error page instead of data. Check the URL and status code, not the commas. - "This object is never closed" points at the opening brace, not the end of the text, so you can find the pair that lost its partner.
- "Extra content after the end of the JSON value" usually means JSON Lines, one value per line. Put the lines in an array with commas between them.
Format, validate or minify?
Each mode has its own page: the JSON validator gives a verdict and a report, and the JSON minifier gives the shortest text.
| Mode | Use it when | You get |
|---|---|---|
| Format | You need to read a response, a log line or a config | Line breaks and indentation, with every string and number copied as written |
| Validate | You want a verdict, or a summary of what is inside | Valid, or the error, plus root type, size, nesting depth and counts, with warnings for duplicate keys |
| Minify | Size matters: a request body, an environment variable, a value in a URL | Spaces and line breaks outside strings removed, with the bytes saved |
"Copied as written" matters more than it sounds. Many formatters read JSON into JavaScript values and write it back, which turns 1.0 into 1 and can round integers above 9,007,199,254,740,991. This one copies each number and string exactly, keeps duplicate keys and reports them, and warns when a number has more digits than a JavaScript number can hold. Put IDs that must stay exact in strings.
Minifying saves less on the network than it looks, because servers usually compress responses with gzip or Brotli, and a minified file is one long line, so keep repository files formatted. Sorting property names A to Z puts two objects with the same keys in the same order, which helps when you compare them with a text diff. Arrays are never reordered.
What it cannot do
- It checks syntax, not meaning. It cannot tell you that
emailis missing or thatageis a string. That needs a JSON Schema and a validator that reads it, and the syntax check comes first. - It does not repair JSON. It points at the first problem and does not guess, because a wrong guess can change your data without you noticing.
- It is not JSON5. The relaxed option adds only comments and trailing commas. Unquoted names, single quotes and hex numbers are still errors.
- Very large input waits for a button. Up to 2 million characters the result updates as you type. Longer text runs when you press it.
Keep API responses and tokens on your device
Real responses hold session tokens, email addresses, customer records and keys. Many free formatters send what you paste to a server. Here the formatting runs in your browser tab. To check, open your browser's developer tools, go to the Network tab, paste some JSON and watch: no request goes out carrying your text.
A JSON Web Token is the classic case. In the usual signed form, its header and payload are only Base64 encoded, not encrypted, so anyone who holds the token can read them, and a live token works like a password until it expires. The JWT decoder also runs in your browser and checks a signature only if you type an HS256, HS384 or HS512 secret. Even so, use a test token when you can. Decode a JWT token explains the claims and why decoding is not verifying, and Base64 explained shows why the parts are readable. The same question for documents is answered in is it safe to upload a PDF to a free website.
Where to go next
If the config is YAML, the YAML formatter re-indents and checks it, keeps your comments and never rewrites values such as 0755 or yes. To move data between JSON and a spreadsheet, use the Data Converter and read the guide to converting CSV to Excel and JSON. To pull a value out of messy text before you format it, test a regular expression first.