← Back to Blog

developer · August 11, 2026

Common JSON Errors and How to Fix Them

JSON's syntax is strict by design, which makes it reliable to parse but unforgiving of small mistakes that would be harmless in JavaScript itself — a single stray character can invalidate an entire payload.

Trailing commas

{"name": "Alex", "age": 30,} — that trailing comma after the last value is valid in JavaScript object literals but invalid in JSON. Remove any comma that appears immediately before a closing brace or bracket. This is one of the most common errors specifically because it's completely legal in JavaScript, so it's an easy habit to carry over without noticing.

Unquoted or single-quoted keys

JSON requires double quotes around every key and every string value — {name: "Alex"} and {'name': 'Alex'} are both invalid. Only {"name": "Alex"} parses correctly. This trips up developers coming from JavaScript, Python, or any language where single quotes and unquoted object keys are perfectly normal.

Missing commas between entries

{"a": 1 "b": 2} is missing a comma between the two key-value pairs. This usually produces an "unexpected token" error pointing near the missing comma's position — the parser expects either a comma or a closing brace after a value, and finds neither.

Mismatched or unclosed brackets

Every opening brace needs a matching closing one, and the same goes for square brackets. In deeply nested JSON, it's easy to close one bracket too few or too many, especially when editing by hand — the resulting error often points to the very end of the file rather than the actual location of the mistake, since the parser doesn't realize something's wrong until it runs out of content.

Unescaped special characters inside strings

A string value containing a literal double quote, backslash, or newline needs those characters escaped. An unescaped quote inside a string value ends the string early as far as the parser is concerned, which usually cascades into a confusing error somewhere later in the file rather than exactly where the real problem is.

Using undefined, functions, or comments

JSON only supports strings, numbers, booleans, null, objects, and arrays — undefined, functions, and comments are all invalid, even though all three are valid JavaScript. This one catches developers who are used to leaving a comment in a config file, not realizing JSON has no comment syntax at all.

Duplicate keys

{"name": "Alex", "name": "Sam"} is technically parseable by many JSON parsers, but it's not something to rely on — the JSON specification doesn't define which duplicate key should win, so different parsers and languages can silently pick different values for the same input. Treat a duplicate key as a bug to fix, even on the rare occasion it doesn't throw an outright error.

Catching these quickly

Rather than scanning by eye, paste the JSON into the JSON Formatter — it will point out exactly where parsing fails, which is usually much faster than manually re-reading a large payload line by line. Once your JSON is valid, the JSON to TypeScript Interface Generator can turn it directly into a typed interface, a good habit for catching shape mismatches before they become runtime bugs.

We use cookies

We use cookies for analytics and to support advertising. You can accept all cookies or decline non-essential ones — change this anytime from Cookie Settings in the footer. Privacy Policy