Skip to main content
SEO & Productivity GuidesHaseeb NawazUpdated November 30, 2026

How to Fix Invalid JSON: 10 Common Errors With Examples

Trailing commas, single quotes, unquoted keys — learn to read JSON error messages, find the real mistake fast, and fix the 10 errors behind almost every invalid JSON file.

SEOproductivity

How to Fix Invalid JSON: The 10 Errors That Break Your Code (With Examples) JSON looks forgiving. It is not. One trailing comma, one pair of single quotes, one comment — and JSON.parse, your API, or your config loader rejects the entire file. Worse, the error message usually points at the character after the real mistake. This guide teaches you to read those messages, then fixes the ten errors that cause almost every failure. First: how to read a JSON error message Parsers report the first position where the input stopped making sense. Unexpected token } in JSON at position 42 usually means the problem is just before position 42: a trailing comma, a missing value, or an unclosed string. Workflow: (1) note the line/column, (2) look at that spot and one or two tokens back, (3) fix one thing, (4) validate again. Repeat — parsers only report the first error, so a file can hide several. A formatter-validator speeds this up enormously: paste the payload into QUORVLY's JSON Formatter QUORVLY tools directory, and valid JSON is pretty-printed instantly while invalid JSON returns the parser's position so you can jump straight to it. The 10 errors

  1. Trailing comma — JavaScript allows it; JSON does not. { "name": "Ava", "active": true, } ← invalid { "name": "Ava", "active": true } ← valid

  2. Single quotes — Keys and strings must use double quotes. {'name': 'Ava'} is a JavaScript/Python habit, not JSON. 3. Unquoted keys — {name: "Ava"} is an object literal, not JSON. Every key needs double quotes. 4. Comments — Standard JSON has no // or /* */. Files like VS Code's settings are JSONC, a different dialect; strict parsers reject comments. 5. Missing comma between items — Often reported at the next key, not where the comma is missing. Look one line up. 6. Values JSON doesn't know — Only strings, numbers, true, false, null, objects and arrays exist. NaN, Infinity, undefined, True and None (Python spellings) are invalid. Use null, or omit the key. In Python, produce JSON with json.dumps() (and allow_nan=False), never by printing a dict. 7. Unescaped characters in strings — A raw line break, tab, or " inside a string breaks parsing. Use \n, \t, ", and double backslashes in Windows paths ("C:\Users\..."). 8. Invalid numbers — No leading zeros (007), no plus sign, no hex (0x1F), and digits are required on both sides of the decimal point (0.5, not .5). 9. Mismatched or missing brackets — In a large minified blob this is invisible; formatting (pretty-printing) reveals structure immediately, which is why formatting is a debugging step. 10. Multiple top-level values / truncated input — Two objects back-to-back are not one JSON document (wrap them in an array, or treat the file as NDJSON). Unexpected end of JSON input means the text stopped early: a truncated download, an unfinished copy-paste, or an unclosed string or bracket. Two traps even experienced developers miss • Big-number rounding. Many browser formatters parse through JavaScript, which silently rounds integers above 2^53 — 9007199254740993 becomes 9007199254740992. If your JSON carries long IDs, treat them as strings, or verify your tool preserves them. • Duplicate keys. {"a": 1, "a": 2} parses "successfully" in most tools, silently keeping only the last value. If a config behaves as if a setting vanished, search the raw text for duplicates. Syntax valid ≠ structure correct Validation has two levels. Syntax validation (this guide) checks grammar. Structure validation checks shape — that email is a string, age is a number, required fields exist. A payload can pass one and fail the other; when an API rejects syntactically valid JSON, the problem is structure, and the API's schema/documentation is your reference. A 60-second debugging checklist

  3. Paste into a validator; read the position. 2. Look at that token and the two before it. 3. Check quotes, commas, brackets — in that order. 4. Search for ', //, True, None, NaN. 5. Pretty-print and eyeball the structure. 6. Re-validate after each single fix. FAQs Why does the same JSON work in my code editor but fail in production? Your editor likely uses a relaxed dialect (JSONC/JSON5) that tolerates comments and trailing commas. Production parsers are strict. How do I fix JSON I didn't write (an API response/log)? Don't hand-edit the source system; validate a copy, find the pattern (it is usually systematic — e.g. every record has a trailing comma), and fix it in your parsing pipeline. Is minified JSON more likely to be invalid? Not more likely — just harder to debug, because everything is "line 1". Format first. Conclusion Almost every invalid JSON file fails for one of ten small reasons. Read the error position backwards, fix one issue at a time, and let a formatter do the visual work. Your future self — debugging at midnight — thanks you.

Sources: ECMA-404 JSON standard (ecma-international.org); MDN Web Docs, JSON.parse / JSON.stringify; language documentation for Python json module.

Related reading

Related QUORVLY tool

JSON Formatter

Put this into practice with the free Quorvly tools — no account needed, nothing uploaded.

All articles