The JSON rules that break most often
From RFC 8259:
- Strings and keys use double quotes. Single quotes are invalid.
- No trailing commas after the last item in an object or array.
- No comments.
//and/* */are not part of JSON. - Only
true,falseandnullas literals, in lowercase. Noundefined,NaNorInfinity. - Control characters inside strings (like a raw line break) must be escaped (
\n).
Is my data safe?
Formatting and validation use your browser's built-in JSON parser. The text is never sent anywhere, so API keys and tokens in the JSON stay on your device. Still, rotate any secret you pasted into a site you don't control.
JSON.parse error messages, and what each one means
Paste the failing JSON above: the formatter shows the line and column. Below are the exact messages from Chrome and Node.js (V8, checked in Node.js 24 on 1 Dec 2026) and, where known, Firefox. Older Chrome versions said Unexpected token } in JSON at position 12 instead.
| Chrome / Node.js | Firefox | Usual cause | Fix |
|---|---|---|---|
Unexpected token '<', "<!DOCTYPE "... is not valid JSON | - | Your code parsed an HTML page (an error page, a 404 or a login redirect) instead of JSON, often fetch() followed by response.json(). | Check the response status and Content-Type before parsing; log the first 200 characters of the body. |
Unexpected end of JSON input | JSON.parse: unexpected end of data | Empty or cut-off text: an empty response body (for example a 204 No Content) or a truncated file. | Check the body isn't empty before parsing. |
Expected double-quoted property name in JSON at position 7 (line 1 column 8) | JSON.parse: expected double-quoted property name | A trailing comma after the last item of an object: {"a":1,} | Remove the comma. |
Unexpected token ']', "[1,]" is not valid JSON | JSON.parse: unexpected character | A trailing comma in an array. | Remove the comma. |
Expected property name or '}' in JSON at position 1 (line 1 column 2) | JSON.parse: expected property name or '}' | Single-quoted keys, {'a':1}: JavaScript object syntax, not JSON. | Use double quotes, or build the text with JSON.stringify(). |
Expected ',' or '}' after property value in JSON at position 7 (line 1 column 8) | - | A missing comma between properties, or a comment (//) inside the JSON. | Add the comma; remove comments (JSON has none). |
Unexpected token 'u', "{"a":undefined}" is not valid JSON | - | undefined, NaN or a function as a value. | Use null, a number or a string. |
Unexpected non-whitespace character after JSON at position 7 (line 1 column 8) | - | Two JSON values back to back, {"a":1}{"b":2}, for example a JSON Lines file read as one document. | Parse it line by line, or wrap the values in an array. |
Related: JWT decoder · password generator
Sources
- RFC 8259: The JSON data interchange format: www.rfc-editor.org/rfc/rfc8259
- V8 source: message-template.h (JSON.parse error texts): github.com/v8/v8/blob/main/src/common/message-template.h
- Firefox source: JSONParser.cpp (JSON.parse error texts): github.com/mozilla-firefox/firefox/blob/main/js/src/vm/JSONParser.cpp
- MDN: SyntaxError: JSON.parse: bad parsing: developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/JSON_bad_parse