DEVELOPER GUIDE

Common JSON syntax errors and how to fix them

Troubleshoot trailing commas, quotation marks, escapes, and missing delimiters.

4 min read•DevToolbox editorial

Replace single quotes with double quotes

JavaScript object syntax and JSON syntax are different. JSON requires double quotes around keys and string values. Bare property names and single-quoted strings are invalid.

Invalid: {name: 'Alex'}
Valid:   {"name": "Alex"}

Remove trailing commas and comments

JSON does not permit a comma after the last object property or array element. It also does not permit // or block comments. Delete comments or store explanatory information in a normal string property if your schema allows it.

Invalid: [1, 2, 3,]
Valid:   [1, 2, 3]

Escape special characters inside strings

A literal double quote needs a backslash. A backslash itself must also be escaped. Actual newlines cannot appear unescaped inside a JSON string; use the two-character escape sequence \n instead.

{"message":"He said \"hello\"","path":"C:\\temp"}

Match every opening delimiter

An object begins with { and ends with }. An array begins with [ and ends with ]. Work from the innermost structure outward, and validate after each correction. Do not use eval to bypass JSON parsing errors.

Put it into practice with a free tool that runs in your browser.
Open JSON Formatter