JSON Basics 8 min read February 14, 2026

JSON Validation Errors Explained: Common Mistakes and How to Fix Them

A complete reference to the most common JSON syntax errors, with before/after code examples, error message explanations, and a strategy for debugging large JSON files.

JSON is intentionally simple, but its strictness surprises developers who come from JavaScript where the syntax is more forgiving. This guide covers every common JSON validation error, why it happens, and exactly how to fix it.

Error 1: Trailing Commas

JavaScript objects and arrays allow trailing commas. JSON does not. RFC 8259 is explicit: a trailing comma after the last element is a syntax error.

json
// INVALID: trailing comma after last property
{
  "name": "Alice",
  "age": 30,
}

// VALID
{
  "name": "Alice",
  "age": 30
}

💡 Tip

VS Code's `settings.json` uses JSONC (JSON with Comments) which allows trailing commas. If you copied something from a VS Code config, remember to strip trailing commas before using in standard JSON contexts.

Error 2: Single Quotes Instead of Double Quotes

JSON requires double quotes for all strings: both keys and values. Single quotes are a JavaScript convention, not valid JSON.

json
// INVALID
{ 'name': 'Alice' }

// VALID
{ "name": "Alice" }

Error 3: Unquoted Keys

In JavaScript, object keys do not need quotes if they are valid identifiers. In JSON, every key must be a double-quoted string, with no exceptions.

json
// INVALID
{ name: "Alice" }

// VALID
{ "name": "Alice" }

Error 4: JavaScript Comments

JSON does not support comments of any kind. Neither `//` single-line nor `/* */` block comments are valid.

json
// INVALID: comments not allowed in JSON
{
  // The user's display name
  "name": "Alice",
  /* deprecated field */
  "legacy_id": null
}

// VALID: remove all comments
{
  "name": "Alice",
  "legacy_id": null
}

If you need a comment-enabled JSON-like format, consider JSONC (used by VS Code), JSON5, or HJSON. All are supersets of JSON that add comment support.

Error 5: Non-JSON Values

JSON supports exactly six value types: string, number, boolean (`true`/`false`), null, object, and array. JavaScript-specific values are invalid:

json
// INVALID: undefined, NaN, Infinity are not JSON values
{
  "result": undefined,
  "ratio": NaN,
  "limit": Infinity
}

// VALID alternatives
{
  "result": null,
  "ratio": null,
  "limit": 1.7976931348623157e+308
}

Error 6: Missing Commas Between Elements

json
// INVALID: missing comma after first property
{
  "name": "Alice"
  "age": 30
}

// VALID
{
  "name": "Alice",
  "age": 30
}

Error 7: Unescaped Special Characters in Strings

Inside JSON strings, certain characters must be escaped with a backslash. A raw newline, tab, or backslash character in a string will cause a parse failure.

json
// INVALID: literal newline in string (invisible in some editors)
{ "message": "Line 1
Line 2" }

// VALID: use escape sequences
{ "message": "Line 1\nLine 2" }

// Required escape sequences:
// \n  newline
// \t  tab
// \r  carriage return
// \\ backslash
// \"  double quote
// \uXXXX  Unicode code point

Error 8: Invalid Number Formats

JSON has specific rules about number formatting that are stricter than most programming languages:

json
// INVALID number formats
{ "a": 01 }     // leading zero (not allowed except "0" alone)
{ "b": 1. }     // trailing decimal point
{ "c": .5 }     // leading decimal point
{ "d": 1e }     // incomplete exponent
{ "e": +1 }     // leading plus sign

// VALID
{ "a": 1 }
{ "b": 1.0 }
{ "c": 0.5 }
{ "d": 1e10 }
{ "e": 1 }

Let the validator do the work for you.

Our JSON formatter detects all of these errors instantly, highlighting the exact line and explaining what is wrong.

Validate JSON Now

Error 9: Unterminated Strings

json
// INVALID: closing quote is missing
{ "name": "Alice }

// VALID
{ "name": "Alice" }

Error 10: Duplicate Keys

Duplicate keys are technically allowed by the JSON specification (RFC 8259 says behavior is undefined), but in practice most parsers accept only the last value for a duplicated key, silently discarding the others. Many validators flag this as an error because it almost always indicates a bug.

json
// AVOID: duplicate keys
{
  "status": "active",
  "status": "inactive"
}
// Most parsers will use "inactive" and silently discard "active"

Debugging Strategy for Large Files

When `JSON.parse()` fails on a large file, the error message gives you a line number and character position. Use these strategies to locate the problem fast:

  1. 1Read the error message first: `SyntaxError: Unexpected token } in JSON at position 1432` tells you the exact character offset.
  2. 2Binary search: If you cannot locate the error, split the file in half. Try parsing the first half. If it succeeds, the error is in the second half. Repeat until you narrow it down.
  3. 3Use jq: `jq . broken.json` outputs a clear error with line number.
  4. 4Validate incrementally: If the JSON was generated by code, add validation in the generator so you know which object failed before the output was concatenated.

Fix Your JSON Errors Instantly

Paste your invalid JSON into our formatter. It highlights the exact line and character of every error with a clear explanation.

Open JSON Validator

Related Articles