Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minutePC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11First identify what is being parsed: JSON.parse(text) parses a string in your code, while response.json() parses an HTTP response body. An “Unexpected token” error means the input could not be parsed as JSON; inspect the actual input near the reported position, correct its syntax or find out what the server returned, then retry.
Find which operation failed
Read the stack trace or the line of code that raised the error. The parser’s input depends on the operation, so begin with the matching diagnostic path.
As an Amazon Associate I earn from qualifying purchases.
| Operation | What it parses | First diagnostic move |
|---|---|---|
JSON.parse(text) |
The exact string supplied by your program | Inspect that string and the syntax around the reported location. |
response.json() |
The HTTP response body | Inspect the response body and status to establish what the server returned. |
request.json() |
The HTTP request body | Verify the request body is valid JSON; distinguish a parsing SyntaxError from body-state or decoding TypeError conditions. |
MDN’s JSON.parse() reference documents malformed-string parsing errors. The Response.json() reference explains that the method reads and parses a response body, and the Request.json() reference documents request-body parsing and related exceptions.
Inspect the input at the failure point
For JSON.parse(text)
Inspect or log the exact string immediately before calling JSON.parse(). Check the parser’s reported position, line, or column, then read the surrounding characters and the preceding value or delimiter. The reported location narrows the search, but the mistake may be earlier—for example, a missing comma can make the next token appear unexpected.
#1 Best Overall
For response.json()
In the browser’s Network panel, inspect the request’s status and response body. If needed, temporarily read the response as text while debugging so you can see what arrived instead of assuming the server returned JSON. An HTML error page, an empty body, or plain text are possible explanations, not conclusions: verify the actual body before deciding what to fix.
For request.json()
Check the body sent with the request and confirm that it is JSON text. A parsing SyntaxError means the body could not be parsed as JSON. A TypeError can instead indicate a body that is locked or disturbed, or a decoding problem; changing JSON punctuation will not resolve those cases.
Check for common JSON syntax errors
JSON is not the same as a JavaScript object literal. JSON property names and strings must use double quotes, and JavaScript conveniences such as trailing commas are not permitted. RFC 8259 specifies that a JSON parser must accept texts that conform to the JSON grammar; it does not make invalid input valid.
- Trailing comma:
[1, 2, 3, 4,]is invalid; use[1, 2, 3, 4]. Likewise, change{"foo": 1,}to{"foo": 1}. - Single quotes or unquoted property names:
{'foo': 1}is invalid JSON. Use{"foo": 1}. - Comments: JSON does not allow comments. Remove them from the JSON text.
- Missing punctuation: Check for missing commas between array items or object properties, and missing colons between a property name and its value.
- Incomplete strings or invalid escapes: Close every string and ensure backslashes introduce valid JSON escape sequences.
- Invalid numbers: A leading zero such as
01is not allowed; use1. A decimal point must be followed by digits, so1.is invalid; use1.0if a fractional form is intended. Exponents must include their required digits. - Extra characters after the value: After the complete JSON value, only JSON whitespace may remain. Remove any additional text.
MDN documents examples such as SyntaxError: Unexpected token ] in JSON at position 13 and SyntaxError: Unexpected token } in JSON at position 12. Exact wording varies among JavaScript engines, so use the location as a clue and inspect the input rather than relying on a particular message format. See MDN’s JSON.parse bad-parsing guide and its JSON.parse examples.
Rank #3
Correct the source, then validate and retry
- Locate the source. For
JSON.parse(), find the code, file, or data that produced the string. For a Fetch response, verify the request route, status, and body to determine whether the server returned the intended payload. - Fix the producer or data. Correct the malformed text where it is created, stored, or returned. If a request is reaching the wrong route or the server is returning an error body, address that underlying issue rather than trying to parse the response as JSON.
- Check the corrected text against JSON grammar. A validator can help spot syntax errors, but it cannot tell you whether the data came from the right source or whether the response is the one your application expected.
- Repeat the same parse operation. Run the same code path with the corrected input. If it still fails, inspect the new input and error location; do not assume the first fix corrected every malformed character.
For the governing syntax and parser requirements, see RFC 8259, section 9.
Quick Recap
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.




