“Unexpected token”, “Unexpected end of JSON input”, “Expected property name or '}'”. JSON error messages are terse, and the line they point to is often not where the mistake is. This guide lists the errors that cause nearly all invalid JSON, shows each one next to its fix, and explains where they come from so you can stop them recurring.

1. Trailing commas

{ "a": 1, "b": 2, }      ✗
{ "a": 1, "b": 2 }       ✓

JavaScript, Python and most modern languages accept a comma after the last item; JSON does not. This is the single most common error in hand-edited config files.

2. Single quotes

{ 'name': 'Asha' }       ✗
{ "name": "Asha" }       ✓

JSON strings and keys must use double quotes. Single quotes usually come from Python’s print(dict) or from JavaScript object literals copied into a JSON file. In Python, use json.dumps(data) instead of str(data).

3. Unquoted keys

{ name: "Asha" }         ✗
{ "name": "Asha" }       ✓

Valid in JavaScript, invalid in JSON.

4. Missing commas

{ "a": 1
  "b": 2 }               ✗  (error is reported at "b", line 2)

A missing comma is reported at the next token, which is why the error line often looks fine. Check the end of the line above.

5. Unclosed brackets and truncated data

“Unexpected end of JSON input” means the parser reached the end while an object, array or string was still open. Causes include a response cut off by a timeout or size limit, a log line truncated at a fixed length, and copying only part of the text. Count your brackets, or let a repair tool close them — but check whether data is missing, because closing brackets does not bring it back.

6. Python and JavaScript literals

{ "ok": True, "value": None }        ✗  (Python)
{ "ok": true, "value": null }        ✓
{ "count": NaN, "x": undefined }     ✗  (JavaScript)

JSON has only true, false and null, in lower case. NaN, Infinity and undefined do not exist; use null.

7. Comments

{ "port": 8080 // default }          ✗

JSON has no comments. Some tools accept “JSON with comments” (VS Code’s settings, TypeScript’s tsconfig.json), but a standard parser will reject them. If a file needs comments, consider YAML or TOML — see YAML vs JSON vs TOML.

8. Unescaped characters in strings

{ "path": "C:\\Users\\new" }   ✓  (each backslash escaped)
{ "path": "C:\Users\new" }       ✗  (\U is not a valid escape, and \n would become a line break)
{ "quote": "He said "hi"" }        ✗
{ "quote": "He said \"hi\"" }      ✓

Inside a string, double quotes and backslashes must be escaped, and raw line breaks and tab characters are not allowed (use \n and \t). Windows paths and text pasted from documents are the usual culprits.

9. Leading zeros and other number formats

{ "pin": 0411, "price": .5, "hex": 0xFF }   ✗
{ "pin": "0411", "price": 0.5, "hex": 255 }  ✓

Numbers cannot start with a zero (except 0 itself or 0.x), must have a digit before the decimal point, and cannot be hexadecimal. Identifiers with meaningful leading zeros — PIN codes, phone numbers — should be strings anyway.

10. Double-encoded JSON

"{\"id\": 1, \"name\": \"Asha\"}"

This is valid JSON — but it is a single string that contains JSON, usually because an object was serialised twice. Your code then sees a string instead of an object. JSON Unescape turns it back into a normal object; the real fix is to serialise once.

11. Byte-order marks and smart quotes

Some editors add an invisible byte-order mark at the start of the file, and word processors replace " with curly quotes “ ”. Both are rejected by strict parsers and are hard to spot by eye. Paste the text into a plain-text editor or a validator that points to the exact character.

Fixing quickly

  1. Paste the text into the JSON Validator to get the line, column and a plain-English description of the first error.
  2. For the common problems above — trailing commas, single quotes, unquoted keys, Python literals, comments, missing brackets — JSON Repair fixes them automatically and shows what it changed. It is especially useful for JSON produced by AI models, which often adds comments or trailing commas.
  3. Validate again, then format the result.

Preventing errors

  • Never build JSON by concatenating strings. Use your language’s serializer (JSON.stringify, json.dumps, encoding/json), which escapes everything correctly.
  • Validate config files in CI, so a broken file fails a build rather than a deployment.
  • Use an editor with JSON syntax highlighting; most errors show up immediately in colour.