Guides / JSON parse errors

Updated October 2, 2026 · 8 minute read

How to fix JSON parse errors

Most JSON errors come from five small syntax mistakes. Learn how to identify the exact character that broke parsing and fix it without guessing.

Start with the parser position

Errors such as Unexpected token, Expected property name, or Unexpected end of JSON input normally include a character offset or line and column. That location is where parsing stopped, not always where the original mistake occurred. Inspect the character at that position and the structure immediately before it.

try {
  const value = JSON.parse(input);
} catch (error) {
  console.error(error.message);
}

Paste the same input into the JSON Formatter and Validator to get readable indentation and an exact syntax location.

1. Property names need double quotes

JavaScript object literals accept unquoted keys and single quotes. JSON does not. Every property name and string value must use double quotes.

// Invalid JSON
{ user: 'Ada', active: true }

// Valid JSON
{ "user": "Ada", "active": true }

2. Remove trailing commas

A comma means another value must follow. JavaScript permits trailing commas in many places, but JSON parsers reject them.

// Invalid
{ "roles": ["admin", "editor"], }

// Valid
{ "roles": ["admin", "editor"] }

3. Escape quotes and backslashes

A quote inside a JSON string closes that string unless it is escaped. Windows paths also need doubled backslashes because a single backslash starts an escape sequence.

{
  "message": "She said \"hello\"",
  "path": "C:\\Users\\Ada\\notes.txt"
}

4. Check missing brackets and braces

Unexpected end of JSON input usually means the document ended while an object, array, or string was still open. Format the document, then match every opening with and every [ with ].

5. JSON has a limited value vocabulary

Valid values are strings, numbers, objects, arrays, true, false, and null. JSON cannot contain comments, undefined, NaN, functions, dates, or hexadecimal numbers.

// Invalid
{ "created": new Date(), "score": undefined }

// Valid
{ "created": "2026-10-02T08:00:00Z", "score": null }

A repeatable debugging checklist

  1. Capture the raw response before another layer transforms it.
  2. Confirm the response is actually JSON, not an HTML error page.
  3. Inspect the parser's line, column, or character offset.
  4. Format the input and fix the first reported error.
  5. Parse again; one syntax error can hide later errors.
  6. Add a test with the failing payload to prevent regression.

Use the related tools