Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

An “Unexpected token” JSON error means the text being parsed is not valid JSON—or the input is not actually the JSON you expected. Find out whether the error came from JSON.parse(), response.json(), or request.json(); inspect that exact input near the reported position; then correct the text or the source that returned it.

First, identify which JSON parser failed

The same-looking parsing error can arise from different inputs. Check the stack trace or the line of code that threw it before editing anything.

Operation What it parses First diagnostic move
JSON.parse(text) The string passed to the function. Inspect that string immediately before parsing. MDN’s JSON.parse error guide
response.json() The body of a Fetch Response. Inspect the response body and status to see what the server actually returned. MDN’s Response.json() reference
request.json() The body of a Fetch Request. Verify the request body is JSON, and distinguish a parsing SyntaxError from body-state or decoding TypeError conditions. MDN’s Request.json() reference

JSON.parse() throws a SyntaxError if its input string does not conform to JSON syntax. A SyntaxError from response.json() means the response body could not be parsed as JSON. Fetch body methods can also fail for other reasons: for example, a body that is locked or already disturbed, or a decoding problem, can produce a TypeError.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Inspect the input and the reported location

For JSON.parse()

Log or inspect the exact string immediately before calling JSON.parse(). If it came from a file, a database, or a generated value, inspect the value at its source as well as the final string. Make sure you are looking at the same input that produced the error.

For a Fetch response

In your browser’s developer tools, open the Network panel and inspect the request’s status, headers, and response body. During debugging, reading the body as text can help reveal whether it contains the expected payload rather than JSON. For example:

const response = await fetch(url);
const body = await response.text();
console.log(response.status, response.headers.get("content-type"), body);

This example reads the body as text, so that same response body cannot then be read again with response.json(). Once you have inspected the content, retry the request or use a fresh response when testing JSON parsing.

For a parser position or line and column

Use the reported location as a starting point, not as proof that the displayed character is the original mistake. The error may appear where the parser can no longer continue, after an earlier missing comma, quote, or delimiter. Read around the location and check the preceding value and punctuation. Messages such as SyntaxError: Unexpected token ] in JSON at position 13 and SyntaxError: Unexpected token } in JSON at position 12 are examples; wording and location details vary between runtimes.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Check for common JSON syntax mistakes

JSON is stricter than a JavaScript object literal. Property names and strings must use double quotes, and JSON does not allow several conveniences JavaScript accepts. RFC 8259 specifies JSON’s grammar; its section 9 says, “A JSON parser MUST accept all texts that conform to the JSON grammar.”

Problem Invalid JSON Valid JSON
Trailing comma [1, 2, 3, 4,]
{"foo": 1,}
[1, 2, 3, 4]
{"foo": 1}
Single-quoted string or property name {'foo': 1} {"foo": 1}
Unquoted property name {foo: 1} {"foo": 1}
Invalid number format 01
1.
1
1.0

Also check for comments, missing commas or colons, incomplete strings, invalid escape sequences, a missing digit after a decimal point, incomplete exponent digits, and extra non-whitespace characters after the JSON value. A JSON document must follow JSON grammar, not merely look like valid code in the surrounding JavaScript.

If the input comes from an HTTP response

Do not assume the parsing code is the problem. The response body may be different from the payload your code expects. An HTML error document, an empty body, or plain text are possible explanations, but inspect the actual response before deciding what happened.

  • Check the request URL and route, response status, headers, and body.
  • If the server returned an error or an unexpected format, correct the route, request, or server response so the body matches what the client expects.
  • If you need to inspect the body as text, do so before parsing it as JSON; Fetch response bodies are consumed when read.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Fix the source, then validate and retry

  1. Identify the failing operation: JSON.parse(), response.json(), or request.json().
  2. Inspect the exact string or body supplied to that operation and examine the reported location plus the punctuation and value before it.
  3. Correct the JSON syntax or fix the producer, request path, or server response that supplied the wrong content.
  4. Check the corrected text against JSON grammar, then rerun the same parsing operation with the corrected input.

A JSON validator can help spot syntax problems, but it cannot tell you why the program received unexpected content. Trace the input back to where it was created or returned when the text itself is not what you expected.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

References: MDN, “SyntaxError: JSON.parse: bad parsing” (last modified July 8, 2025); MDN, “Response: json() method”; IETF RFC 8259, “The JavaScript Object Notation (JSON) Data Interchange Format” (December 2017); MDN, “JSON.parse()”; MDN, “Request: json() method”.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.