Home · Blog · Common JSON Errors
JSON · Tutorial

The Most Common JSON Parsing Errors, Explained

SyntaxError: Unexpected token } in JSON at position 47. We've all seen it. Here are the actual root causes — and how to fix each one in seconds.

7 min read·Updated June 2026

JSON looks simple, which is exactly why it bites. The spec is small but unforgiving — anything that's almost JSON (like a JavaScript object literal, or a YAML fragment, or a pretty-printed log line) will fail to parse. These are the errors we see most often, in roughly the order they show up in real codebases.

1. Trailing commas

The single most common mistake. JavaScript and Python both tolerate trailing commas in arrays and objects; JSON does not.

{
  "name": "Ada",
  "tags": ["math", "logic",]   // ← invalid
}

Remove the comma after "logic". If your data comes from a code generator, look for an extra + "," in the template.

2. Single quotes instead of double quotes

JSON strings and keys must use double quotes. Single quotes are a JavaScript convention only.

{ 'id': 1, 'name': 'Ada' }   // ← invalid JSON
{ "id": 1, "name": "Ada" }   // ✓ valid

3. Smart quotes from a word processor

Pasting JSON from Notion, Word, Slack or Google Docs often replaces straight quotes with typographic quotes: " " ' '. They look right and fail to parse.

FixPaste your JSON into a tool that highlights the failing position — like the JSON Formatter — and replace smart quotes with straight ones.

4. Unquoted keys

JavaScript lets you write { id: 1 }. JSON does not.

{ id: 1 }       // ← invalid
{ "id": 1 }     // ✓ valid

5. Comments

JSON has no comment syntax. No //, no /* */, no #. If you need comments, use JSONC, JSON5, or YAML — and convert before parsing.

6. NaN, Infinity, undefined

The JSON spec only allows finite numbers, strings, booleans, null, arrays and objects. NaN and Infinity are JavaScript-only. Serializers often emit them by mistake.

{ "ratio": NaN }       // ← invalid
{ "ratio": null }      // ✓ common substitute

7. Unescaped control characters in strings

Literal newlines, tabs, or backslashes inside a JSON string break the parser.

{ "msg": "line one
line two" }            // ← invalid
{ "msg": "line one\nline two" }   // ✓ valid

8. UTF-8 BOM at the start of the file

A byte-order mark (\uFEFF) at position 0 is invisible in most editors but trips up strict parsers. The error message often says "Unexpected token " with no visible character.

Re-save the file as UTF-8 without BOM, or strip the first byte before parsing:

const clean = raw.replace(/^\uFEFF/, '');
const data  = JSON.parse(clean);

9. Truncated payloads

When a network request fails mid-stream, you get well-formed JSON up to a point and then nothing. The parser reports an unexpected end of input. Check the response's Content-Length against the body length, and verify your HTTP client isn't aborting on timeout.

10. Wrong root type

A JSON document's root must be a value — usually an object or array. A bare identifier or a stray HTML error page (very common from misconfigured proxies) is not JSON.

Quick debugIf JSON.parse fails on production data, log the first 200 characters of the response. Nine times out of ten you'll find an HTML error page from a load balancer.

Debugging workflow

  1. Paste the payload into the JSON Formatter. The error will point to a specific line and column.
  2. If the source is a file, check the byte length and the first few bytes for a BOM.
  3. If the source is an HTTP response, log the Content-Type header — you may be parsing HTML.
  4. If two payloads should match but don't, run them through JSON Diff to see the structural change rather than guessing.

FAQ

Why does JSON.parse fail on valid-looking JSON?
Usually because the source includes a trailing comma, single quotes, smart quotes from a word processor, an unescaped newline inside a string, or a leading UTF-8 BOM. All are common in copy-pasted JSON.
Is NaN valid JSON?
No. The JSON spec only allows finite numbers. NaN, Infinity and -Infinity are invalid. Serialize them as null or a sentinel string and document the choice.
Can JSON keys be unquoted?
No. JSON requires every key to be a double-quoted string. JavaScript object literals are more permissive.
What's the difference between JSON, JSONC and JSON5?
JSON is the strict spec. JSONC adds comments (used by VS Code's tsconfig.json). JSON5 adds comments, trailing commas, unquoted keys and more. Strip comments and trailing commas before passing to a strict parser.