If a formatter or parser says your input is "invalid JSON", the data almost always contains something that is fine in JavaScript, Python or YAML but not allowed by the much stricter JSON specification (RFC 8259). This guide walks through how validation works, the errors you will see most often, and how to fix each one quickly.
Validation has two levels, and it helps to know which one is failing:
JSON.parse() does.email is a string and age is a number. That needs a schema, which is covered in JSON Schema basics.Everything below is about syntax. To check syntax in the browser, paste your data into the JSON Formatter. If it parses, the editor formats it. If not, it highlights the line and column where parsing stopped.
Parsers report the first position where the input stopped making sense, which is often just after the real mistake. A message like Unexpected token } in JSON at position 42 usually means the problem is on the line before: a trailing comma, a missing value, or an unclosed string. Jump to the reported line, then look one or two tokens back.
JSON only accepts double quotes. Unquoted keys and single quotes come from JavaScript object literals and Python dictionaries.
Not valid JSON (unquoted key, single quotes):
text{a: 'hello'}
Valid JSON:
json{"a": "hello"}
If you copied the output of Python's print(dict), use json.dumps(data) instead, which produces real JSON.
A comma after the last item in an object or array is allowed in modern JavaScript but not in JSON.
Not valid JSON (trailing comma):
text{"a": 1,}
Valid JSON:
json{"a": 1}
Neither // nor /* */ comments are part of JSON. Some tools accept "JSON with comments" (for example tsconfig.json in VS Code), but a standard parser will reject them.
Not valid JSON (contains a comment):
text{ // comment "a": 1 }
Valid JSON:
json{ "a": 1 }
If you need to document a field, add a separate key such as "_comment": "...", or use a format that supports comments, such as YAML (see JSON vs YAML).
JSON supports exactly six kinds of values: objects, arrays, strings, numbers, true/false and null. JavaScript values like undefined, NaN and Infinity have no JSON representation.
Not valid JSON:
text{"count": NaN, "limit": Infinity, "value": undefined}
Valid JSON (use null, or leave the key out):
json{"count": null, "limit": null}
Note that JSON.stringify() silently drops keys whose value is undefined and turns NaN into null, so the problem usually appears when JSON is written by hand or generated with string concatenation.
" inside a string breaks parsing. Use \n and \" instead; see Escape JSON strings.007, +5, .5 and hexadecimal like 0x1F are not valid JSON numbers. Write 7, 5, 0.5 and 31." into curly quotes (“ ”), which JSON does not accept.In JavaScript, wrap JSON.parse in a try/catch and log the message:
javascripttry { const data = JSON.parse(text); } catch (err) { console.error('Invalid JSON:', err.message); }
In Python, json.loads(text) raises json.JSONDecodeError, whose lineno and colno attributes point to the problem.
Different whitespace and indentation make diffs noisy. Once both documents are valid, format them the same way and then compare the two JSON files.