← Tools

Common JSON Errors and How to Fix Them Instantly

📅 June 12, 2026  |  🏷️ JSON  |  ⏱️ 5 min read

You paste JSON into your parser and get: "Unexpected token at position 142" — and now you're squinting at a wall of text looking for a single missing comma. Sound familiar?

90% of JSON errors are the same 5 mistakes, repeated endlessly. Here's how to spot and fix each one in seconds.

Error #1: Trailing Comma

The #1 JSON mistake. JSON does not allow a comma after the last item in an array or object.

// ❌ WRONG — trailing comma after "editor"
{
  "roles": ["admin", "editor",]
}
// ✅ FIX — remove the trailing comma
{
  "roles": ["admin", "editor"]
}

Why this happens: JavaScript allows trailing commas, so developers writing config files in JS style accidentally bring this habit to JSON. ESLint even has a comma-dangle rule that encourages trailing commas in JS — bad habit for JSON.

Error #2: Unquoted Keys

All JSON object keys must be double-quoted strings.

// ❌ WRONG — unquoted keys
{
  name: "Alice",
  age: 30
}
// ✅ FIX — quote all keys
{
  "name": "Alice",
  "age": 30
}

Why this happens: JavaScript object literals don't require quoted keys. Developers write JavaScript-style objects and treat them as JSON. They're not the same.

Error #3: Single Quotes Instead of Double Quotes

JSON requires double quotes for strings. Single quotes are not valid JSON.

// ❌ WRONG — single quotes
{
  'name': 'Alice',
  'message': 'Hello, world!'
}
// ✅ FIX — double quotes everywhere
{
  "name": "Alice",
  "message": "Hello, world!"
}

Error #4: Missing or Extra Brackets

Unbalanced curly braces {} or square brackets [].

// ❌ WRONG — missing closing brace
{
  "users": [
    {
      "name": "Alice"
    // ← missing } and ]
}
// ✅ FIX — close every opening bracket
{
  "users": [
    {
      "name": "Alice"
    }
  ]
}

Quick fix tip: In VS Code, click on a bracket — the matching bracket highlights. If nothing highlights, you have an unbalanced bracket somewhere.

Error #5: Comments in JSON

JSON does not support comments. No //, no /* */.

// ❌ WRONG — comments
{
  // User object
  "name": "Alice",
  /* Active status */
  "active": true
}
// ✅ FIX — remove comments, or use a "_comment" field
{
  "_comment": "User object",
  "name": "Alice",
  "_comment_active": "Active status",
  "active": true
}

JSON5 and JSONC: Some config file formats (like VS Code's settings.json, tsconfig.json) support comments because they use JSONC (JSON with Comments). But standard JSON parsers will reject it.

Bonus: Non-JSON Data Types

// ❌ WRONG — these are not valid JSON types
{
  "date": new Date(),       // not valid
  "value": undefined,       // not valid
  "fn": function() {},      // not valid
  "num": NaN,               // not valid
  "inf": Infinity           // not valid
}
// ✅ FIX — use strings or null
{
  "date": "2026-06-12T00:00:00Z",
  "value": null,
  "fn": null,
  "num": null,
  "inf": null
}

Valid JSON types: String, Number, Boolean, null, Array, Object. That's it. No Date, undefined, functions, NaN, or Infinity.

The Fastest Way to Fix JSON Errors

  1. Paste your JSON into the DevTools JSON validator.
  2. The tool instantly shows the exact error position (line + character).
  3. Check the line above the error — in 90% of cases, the problem is a missing comma, extra comma, or unquoted key on the previous line.
💡 Pro Tip: "Unexpected token" at a specific position almost always means the character before that position is wrong. The parser hit an invalid character and stopped. Look one character to the left of where the error points.
Fix JSON Errors Instantly — Free

Paste your JSON, see errors highlighted, fix and format in seconds.

Open JSON Validator →
← Back to DevTools Blog