JavaScript JSON debugging

JavaScript JSON.parse Errors

JavaScript JSON.parse converts a JSON string into a JavaScript value. It throws a SyntaxError when the input is not strict JSON, but the exact message varies across JavaScript engines and browsers.

Quick answer

Before calling JSON.parse, confirm you actually have a string containing JSON. Many parsing bugs come from HTML responses, empty strings, already-parsed objects or JavaScript object-literal syntax that is not valid JSON.

Unexpected token

Inspect the character mentioned by the error and the syntax immediately before it. Common causes are missing commas, single quotes, unquoted keys, trailing commas and parsing an HTML response.

Unexpected end of JSON input

The string is usually empty, truncated or missing a closing quote, brace or bracket. Log the string length and final characters before parsing.

Avoid double parsing

fetch(...).then(r => r.json()) already parses the JSON body. Calling JSON.parse on the resulting object is incorrect. Know whether each boundary returns text or an already-decoded value.

Safer parse debugging

try {
  const value = JSON.parse(text);
} catch (error) {
  console.error(error.message);
  console.error(text.slice(0, 200));
}

Related JSON tools and guides

Frequently asked questions

What does JSON.parse return?

It returns the JavaScript value represented by the JSON string: object, array, string, number, boolean or null.

Can JSON.parse read single quotes?

No. JSON strings and object property names require double quotes.

Does response.json() use JSON.parse?

Conceptually it parses the response body as JSON for you, so you normally should not JSON.parse the returned value again.

Source-backed reference

JSON standards quick reference

Concise, standards-backed facts for developers working with JSON debugging and validation. Each claim is linked to the evidence registry and resolves to a primary standard or platform reference so it can be independently verified.

JSON standard
JSON is a text format for serializing structured data, with syntax defined by interoperable standards rather than by FixTools.
Strings and object keys
JSON strings and object member names use double quotation marks. Single-quoted strings are not valid standard JSON syntax.
Trailing commas
Standard JSON grammar does not allow a comma after the final member of an object or the final element of an array.
Parser behavior
JSON.parse() parses JSON text into a JavaScript value and raises a SyntaxError when the input is not valid JSON.

Common invalid → valid JSON examples

Trailing comma

{"a":1,}{"a":1}

Single-quoted key

{'a':1}{"a":1}

Unsupported literal

{"score":NaN}{"score":null}

Built for verification, not just extraction

Direct answers are paired with source-specific evidence. This keeps technical claims independently verifiable and gives search and answer systems a clearer provenance trail than unsupported summary copy.