Skip to content

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

✗ Broken code
JSON.parse("{'name': 'Ada'}");  // SyntaxError: single quotes
JSON.parse('{"name": "Ada",}');  // SyntaxError: trailing comma
✓ Fixed code
JSON.parse('{"name": "Ada"}');  // Valid JSON

JSON 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

← Back to language