Lesson 5

Common JSON Errors

Trailing commas, comments, single quotes, and other frequent mistakes.

Invalid JSON usually fails fast at parse time. Recognizing these patterns saves time when debugging API integrations or config files.

Trailing commas

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

JavaScript allows the comma after 2; JSON does not. Remove commas before } or ].

Single quotes

{ 'name': 'Ada' }

JSON strings must use double quotes ".

Unquoted keys

{ name: "Ada" }

Keys are strings and require double quotes: { "name": "Ada" }.

Comments

// not allowed in JSON
{ "x": 1 }

Use README files or JSON Schema descriptions for documentation—not inline comments.

Invalid literals

  • True / False — must be lowercase true / false
  • undefined — omit the property or use null
  • NaN, Infinity — not valid JSON numbers

Smart quotes and invisible characters

Copying from Word or web pages may insert " " instead of ". Editors may add BOM or non-breaking spaces. If parsing fails with a cryptic position error, re-type quotes or paste through a plain-text editor.

Almost-JSON from JavaScript

When developers log objects or copy from browser consoles, output may look like JSON but include functions, undefined, or unquoted keys. Always run through a strict parser before treating text as JSON.

Fixing workflow

  1. Read the parser error line and column.
  2. Check the line above closing brackets for extra commas.
  3. Verify all strings and keys use ".
  4. Remove comments and JavaScript-only syntax.

These rules are strict by design—strictness is what makes JSON portable across systems.

When you want to practice, use the related DevCove tool — optional, not part of this lesson.

Open related tool

Back to course overview