Developer Tools guide
9 Common JSON Syntax Errors and How to Fix Each One
ยท 4 min read
Most invalid JSON comes down to a short list of mistakes: a trailing comma, single quotes, unquoted keys, comments, or a value JSON doesn't support, like NaN. A validator parses your text with a strict JSON parser and reports the first spot where it breaks, as a line and column. Fix that spot, validate again, and repeat until it passes.
JSON is stricter than the JavaScript or Python you probably write every day. The grammar in RFC 8259 is small, and anything outside it is rejected, even when it looks harmless. Below are the errors you'll actually hit, with the messages a Chromium-based browser shows. Firefox and Safari word these differently, but the position is reported the same way.
How do you read a JSON error message?
Paste JSON into the JSON Validator and it checks the text as you type. Valid input shows a green confirmation that also describes the top-level value, such as โ Valid JSON โ the document is an object with 4 key(s). Invalid input shows something like:
Invalid JSON: Expected double-quoted property name (line 1, column 8).
The position marks where the parser gave up, which is not always where the mistake is. A missing comma is reported at the start of the next value, and an unclosed string is reported at the end of the document. If the flagged spot looks fine, look one token earlier.
The nine errors, with fixes
1. Trailing comma
{ "name": "Emojar", "valid": true }
Message: Expected double-quoted property name. After a comma the parser expects another key, so it complains when it finds }. Fix: delete the last comma. This is the most common error, because JavaScript, TypeScript and Python all allow trailing commas.
2. Single quotes
{ "name": "Ada" }
Message: Expected property name or '}'. JSON strings and keys must use double quotes. Fix: replace ' with ". Be careful with apostrophes inside values, like "Ada's". Those are fine inside a double-quoted string.
3. Unquoted keys
{ "name": "Ada" }
Same message as above. JavaScript object literals allow bare keys, JSON doesn't. Fix: put every key in double quotes.
4. Comments
{
"port": 8080 // default
}
Message: Expected ',' or '}' after property value. JSON has no comment syntax. Fix: remove the comment, or move it into the data as a field like "_comment": "default". Files such as tsconfig.json accept comments because their tools use a looser parser (JSONC). Standard JSON parsers don't.
5. Missing comma between members
{"a": 1
"b": 2}
Message: Expected ',' or '}' after property value (line 2, column 2). The position points at "b", the line after the mistake. Fix: add the comma at the end of line 1.
6. Leading zeros
{ "zip": 02134 }
Message: Unexpected number. JSON numbers can't start with 0 unless the number is exactly 0 or a decimal like 0.5. Fix: if the leading zero matters (postcodes, product codes), make it a string: "02134".
7. NaN, Infinity and undefined
{ "ratio": NaN }
Message: Unexpected token 'N'. JSON only allows finite numbers, strings, true, false, null, arrays and objects. Fix: use null, or a string if you need to keep the meaning. Note that JSON.stringify in JavaScript quietly turns NaN into null, while some other languages' serializers write NaN anyway.
8. Raw line breaks or tabs inside strings
{"note": "line one
line two"}
Message: Bad control character in string literal. Control characters must be escaped. Fix: write \n for a newline and \t for a tab inside the string.
9. Two documents back to back
{"a":1}{"b":2}
Message: Unexpected non-whitespace character after JSON. This happens when you paste several log lines or a JSON Lines file at once. Fix: validate one document at a time, or wrap them in an array: [{"a":1},{"b":2}].
A quick workflow for fixing broken JSON
- Paste the text into the input. It's checked on every keystroke, so there's no button to press.
- Jump to the line and column in the message. If nothing looks wrong there, check the character just before it.
- Fix that one error. The status updates right away and either turns green or moves on to the next error.
- Repeat until you see the green check, then copy the JSON back.
Click Load sample to see a document with a deliberate trailing comma and practice on it.
What does the validator not check?
It answers one question: is this text syntactically valid JSON? It doesn't check:
- Schema. Whether
ageis a number, or whether required fields are present, is a JSON Schema question, and this tool doesn't do schema validation. - Duplicate keys.
{"a":1,"a":2}is accepted, as it is by most parsers, and the last value wins. RFC 8259 only says names should be unique. - Number precision.
12345678901234567890is valid JSON, but JavaScript can't hold it exactly. Send large IDs as strings.
Once your JSON is valid, the JSON Formatter will indent it for reading. If you're looking at a YAML config instead, YAML to JSON reports YAML syntax errors the same way.
FAQ
Why does my JSON work in JavaScript but fail here?
A JavaScript object literal isn't JSON. JS accepts single quotes, bare keys, trailing commas, comments and undefined, and JSON accepts none of them. If you copied an object out of source code, check those five things first.
Is an empty object or a bare value valid JSON?
Yes. {}, [], "hello", 42 and null are all complete JSON documents under RFC 8259. The validator will report, for example, that the document is a number. An empty input, though, isn't JSON at all.
Does pasting sensitive data into the validator expose it?
No. Validation uses your browser's built-in JSON.parse, and the text stays on your device.
Find and fix your next syntax error with the JSON Validator.
