W

Common JSON Errors

JSON.parse fails when text violates the JSON specification. Browsers and validators report position or line/column to help you locate mistakes. Most errors come from treating JSON like JavaScript object literals.

Trailing commas

JSON forbids a comma after the last element: `[1,2,]` is invalid.

Comments and unquoted keys

Use a JSON5 parser if you need comments; standard JSON does not allow them.

Fixing errors quickly

Use a JSON validator that reports line and column numbers. Fix the first reported error before re-running — later errors are often cascading. Format valid JSON only after syntax passes.

API integration

When an API returns 400 with invalid JSON body, log the raw response text and validate offline. Copy-paste errors from Postman or curl often introduce invisible characters.

Common mistakes

  • Trailing comma

    Delete the comma after the final array/object item.

  • Single-quoted strings

    Replace `'` string delimiters with `"`.

  • Undefined or NaN

    Use `null` or quoted strings; JSON has no undefined.

Related tools

See also

Explore related topics