JSON Parse Error
Quick summary
JSON.parse fails because the input string is not valid JSON — usually due to single quotes, trailing commas, or unquoted keys.
Why this happens
Single quotes instead of double quotes for strings or keys
Trailing comma in an array or object
Unquoted property keys
Undefined or function values in the data
Minimal example
JSON.parse("{'name': 'Ada'}"); // SyntaxError: single quotes
JSON.parse('{"name": "Ada",}'); // SyntaxError: trailing commaJSON.parse('{"name": "Ada"}'); // Valid JSONJSON requires double quotes for all strings and keys, and does not allow trailing commas. Fix both issues to make the JSON valid.
How to diagnose
Check the error message — it usually points to the position of the syntax error
Paste the JSON into a JSON validator or formatter tool
Look for single quotes, trailing commas, or unquoted keys
How to fix
Replace single quotes with double quotes
Remove trailing commas
Wrap all keys in double quotes
Remove undefined or function values before stringifying
How to prevent
Use JSON.stringify to generate JSON — it always produces valid JSON
Use a JSON linter in your editor or build process
Related Resources
Related Glossary
Related Lessons
- JSON
Learn JSON syntax.
Related Practice
- Find the JSON Mistake
Practice fixing JSON.