What the error means
After a value, the parser needs either a comma (more items follow) or the closing brace or bracket. It found something else, most often the start of the next key because a comma is missing.
The message looks like this in Chrome, Edge and Node.js (Firefox and Safari use different wording for the same problems):
Expected ',' or '}' after property value in JSON at position 8 (line 1 column 9)
Expected ',' or ']' after array element in JSON at position 3 (line 1 column 4)Common causes
A missing comma between properties
Typically after adding a new line by hand. The reported position is the start of the second key, because that is where the parser gave up.
Broken: {"a": 1 "b": 2}
Valid: {"a": 1, "b": 2}A missing comma between array items
The array version of the same mistake mentions a closing bracket.
Broken: [1 2]
Valid: [1, 2]Comments in the JSON
// and /* */ comments are not part of JSON. After a value, a comment looks like an unexpected character, so you get this same error.
Broken: {"a": 1 // note
}
Valid: {"a": 1}A merge conflict or pasted text
Lines such as <<<<<<< HEAD left over from a merge, or a log line pasted in the middle of the data, break the structure at that point.
How to find the problem
- Paste the text that you passed to JSON.parse into the editor above. The status bar shows the line and column of the first problem, and Go to error jumps there.
- Remember that the position in the message is where the parser gave up, which is often one token after the real mistake. Look at the character before it as well.
- If the text came from a request, log the raw response text before parsing it. In the browser, open the Network tab, select the request and read the Response tab.
Find the first broken line quickly
try {
JSON.parse(text);
} catch (err) {
// Newer engines include the line and column in the message
console.error(err.message);
}Frequently asked questions
The error points at the second key, but the missing comma is above it. Why?
The parser only notices a problem when it reads the next token. The real mistake is the end of the previous line, where a comma should be.
Does JSON have comments?
No. If you need comments, keep them in a separate field such as "_comment", or use a format that supports them like JSONC or YAML.