Why JSON.parse fails: the 6 errors behind most invalid JSON
JSON looks like a JavaScript object, but the grammar is much stricter, and a parser rejects the whole document at the first rule it breaks. Almost every "Unexpected token" error comes from one of the six mistakes below. Paste your text into the JSON formatter to see the position of the first one.
1. A trailing comma
{ "a": 1, "b": 2, }JSON does not allow a comma after the last item in an object or array. Delete it: { "a": 1, "b": 2 }.
2. Single quotes
{ 'name': 'Ada' }Strings and keys must use double quotes. Replace every single quote that delimits a string with a double quote.
3. Unquoted keys
{ name: "Ada" }This is valid JavaScript but not JSON. Every key is a double-quoted string: { "name": "Ada" }.
4. Comments
{ "a": 1 // the count }JSON has no comment syntax, neither // nor /* */. Remove them, or store notes in a normal field such as "_note". Config formats like JSONC and JSON5 allow comments, but a standard JSON parser rejects them.
5. Values that only exist in JavaScript
undefined, NaN, Infinity and function values are not JSON. Use null for a missing value. Numbers also cannot have leading zeros (007) or a trailing dot (5.).
6. Unescaped characters inside strings
A literal line break or tab inside a string is invalid; write \n or \t. A double quote inside a string is written \", and a backslash as \\. Windows paths are a common source: "C:\temp" must be "C:\\temp".
Reading the error message
Engines phrase the error differently. Older ones say something like "Unexpected token } in JSON at position 12"; current ones say "Expected double-quoted property name in JSON at position 12 (line 1 column 13)". The position is where the parser gave up, which is at or just after the real mistake. Look one token back: a trailing comma is reported at the closing brace that follows it.
Still stuck? Bisect: remove half the document and check again, repeating until the error moves.