How JSON Parsing Errors Work
When JSON.parse() encounters invalid syntax, it throws a SyntaxError with a message describing the problem and the character position where parsing failed. The key to fast debugging is understanding what each error message actually means.
1try {2 JSON.parse('{"name": "Alice",}');3} catch (err) {4 console.log(err.message);5 // "Expected double-quoted property name in JSON at position 17"6 // Position 17 = the closing brace } right after the trailing comma7}The 15 Most Common JSON Errors
Single quotes instead of double quotes
Broken
{'name': 'Alice'}Fixed
{"name": "Alice"}JSON requires double quotes for all strings and keys. Single quotes are valid in JavaScript but not in JSON.
Trailing comma
Broken
{"a": 1, "b": 2,}Fixed
{"a": 1, "b": 2}A comma after the last property or array item is invalid. JavaScript allows it, JSON does not.
Unquoted keys
Broken
{name: "Alice"}Fixed
{"name": "Alice"}All object keys must be strings enclosed in double quotes.
Comments in JSON
Broken
{
// user name
"name": "Alice"
}Fixed
{
"name": "Alice"
}JSON has no comment syntax. Use JSONC for configs that need comments, or move docs to a separate file.
Unescaped newlines in strings
Broken
{"bio": "Line 1
Line 2"}Fixed
{"bio": "Line 1\nLine 2"}Literal newline characters inside strings are invalid. Use the \\n escape sequence.
Unescaped backslashes
Broken
{"path": "C:\Users\file"}Fixed
{"path": "C:\\Users\\file"}Backslashes must be doubled. A single backslash starts an escape sequence.
Using undefined or NaN
Broken
{"value": undefined}Fixed
{"value": null}undefined, NaN, and Infinity are not valid JSON values. Use null for absent values.
Leading zeros on numbers
Broken
{"code": 007}Fixed
{"code": 7}Numbers cannot have leading zeros in JSON (except 0 itself and 0.x decimals).
Capitalized booleans or null
Broken
{"active": True, "x": Null}Fixed
{"active": true, "x": null}JSON uses lowercase true, false, and null. Capitalized versions are not valid.
Missing comma between items
Broken
{"a": 1 "b": 2}Fixed
{"a": 1, "b": 2}Key-value pairs and array items must be separated by commas.
Extra comma between items
Broken
[1,, 3]Fixed
[1, 3]Double commas create an implicit undefined slot, which JSON does not support.
Unclosed string
Broken
{"name": "Alice}Fixed
{"name": "Alice"}Every opening double quote must have a matching closing quote on the same line.
Truncated JSON
Broken
{"users": [{"id": 1Fixed
{"users": [{"id": 1}]}Every opening brace and bracket must be closed. Truncated data often comes from network timeouts.
BOM (Byte Order Mark)
Broken
{"name": "Alice"}Fixed
{"name": "Alice"}Some text editors add an invisible BOM character at the start. Strip it before parsing.
Mixing JSON with JavaScript
Broken
{name: "Alice", fn: () => {}}Fixed
{"name": "Alice"}JSON is data only. Functions, methods, and unquoted identifiers are JavaScript, not JSON.
Debugging Strategy
Step 1: Locate the Error Position
Most parsers report the character position or line number. Start there and look for the patterns above.
Step 2: Use a Validator Tool
Paste your JSON into a JSON Validator to get line-by-line error reports with clear messages.
Step 3: Simplify and Isolate
If the JSON is large, cut it in half and validate each half separately. This binary search narrows the error quickly.
Step 4: Check Encoding
Open the file in a hex editor or check Content-Type headers. JSON must be UTF-8.
Try These Tools
Prevention Checklist
Try It — Fix This Broken JSON
This JSON has five errors. Can you fix all of them?
Try It Yourself
Fix single quotes, trailing comma in array, capitalized boolean, comment, and undefined