DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
World desk4 min

Why Does This JSON Error Quote the Response—and Where Does V8 Cut It?

A V8 JSON error quotes context from the parser’s input. Learn what its excerpt can reveal, what the measured 20-character boundary means, and how to diagnose an HTML or otherwise unexpected response.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

If response.json() or JSON.parse() throws an error such as Unexpected token '<', "<!DOCTYPE "... is not valid JSON, the quoted text is a context excerpt from the string the parser received. It can reveal that the response was HTML rather than JSON, but the excerpt is not necessarily the whole body. In a measurement on Node.js v24.13.0 with V8 13.6, invalid inputs up to 20 characters were quoted whole; at 21 characters, V8 abbreviated the excerpt. That boundary is a measured behavior for that runtime, not a guarantee for every V8 release or JavaScript engine.

What does the quoted text in a JSON error mean?

The quoted fragment is text from the input that the JSON parser was asked to parse. It gives context around the parse failure; it is not a server-generated explanation of what went wrong. If the input starts with <!DOCTYPE or another HTML tag, the parser may report a leading < because that character is not a valid start for the JSON value it expected.

As an Amazon Associate I earn from qualifying purchases.

That makes the excerpt useful evidence, not a complete diagnosis. A response beginning with HTML may be an error page, login page, or application fallback. The unexpected character alone does not establish which one. Check the response metadata and body before deciding why the request returned it.

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

Why does V8 show 20 characters, then shorten the excerpt?

In a measurement reported by Coding Now in 2026, Node.js v24.13.0, using V8 13.6, displayed invalid inputs of 20 characters or fewer in full. At 21 characters, the message used an abbreviated excerpt. For an invalid character at the very start of a longer input, the excerpt was the first 10 characters followed by an ellipsis. This is a runtime-specific measurement, not a cross-version guarantee.

V8’s parser implementation explains why excerpts vary by failure location. Its GetErrorMessageWithEllipses logic uses kMaxContextCharacters, set to 10 in the source reviewed, and chooses a start, surrounding, or end context based on where the unexpected token occurs. A failure farther into a string can therefore show text around that position, with an ellipsis at the beginning, the end, or both. It is not accurate to assume every error reveals the first 10 characters.

The implementation is on V8’s changing main branch, so its current behavior should not be treated as a permanent interface contract: V8 JSON parser source. The 20/21-character observation and runtime versions are reported by Coding Now’s 2026 article.

How can you tell whether the server returned HTML instead of JSON?

Use the browser’s Network panel to inspect the request that failed. Compare the response status, content type, final URL, redirect state, and body. An Accept: application/json request header expresses what the client prefers; it does not prove the server returned JSON.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Status: Check whether the HTTP response was successful or an error. fetch() generally resolves to a Response even for HTTP error statuses; parsing the body is a separate operation that can fail.
  • Content-Type: See whether the response declares JSON or a type such as text/html. A declared type is evidence, but inspect the body if it does not match what you expected.
  • Final URL and redirects: Confirm the request ended at the expected endpoint. A followed authentication redirect, for example, can result in a login page being returned instead of API data.
  • Body: Look at the response itself. HTML, plain-text gateway errors, an empty body, and a JSON payload point to different problems.

A Coding Now example illustrates why these checks matter: a missing route on its Next.js 16 development server returned a 404 HTML page with Content-Type: text/html; charset=utf-8, despite the request including Accept: application/json. That is an example from that setup, not a promise about how every Next.js server or missing route behaves.

How should you inspect the body in JavaScript without losing it?

For diagnostics, read the body as text once, capture the response metadata, and then parse that saved string if it is appropriate to do so. Reading a response body consumes its stream, so do not expect to call res.text() after a failed res.json() and still have the original body available.

const res = await fetch(url);
const contentType = res.headers.get("content-type") ?? "";
const body = await res.text();

if (!res.ok || !contentType.toLowerCase().includes("application/json")) {
  console.error({
    status: res.status,
    contentType,
    url: res.url,
    redirected: res.redirected,
    bodyExcerpt: body.slice(0, 300),
  });
  throw new Error("Expected a successful JSON response");
}

const data = JSON.parse(body);

This uses a simple substring check as an example, not a full MIME-type parser. Adapt the condition to the API’s actual response types and error contract. The excerpt is capped to limit logging; choose a limit appropriate for your environment and avoid logging sensitive response content.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

What common causes should you check?

Once the body and metadata are visible, investigate the cause that fits the evidence rather than guessing from the first character alone.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Wrong or missing route: A relative URL may resolve to a different path than intended, or the requested route may not exist.
  • Authentication redirect: The request may have ended at a login page rather than the API endpoint. Check the final URL and redirect state.
  • Application fallback: A single-page application may serve its HTML shell for an unrecognized path.
  • Server or gateway error: The body may be an HTML error page, plain-text message, or another non-JSON response.
  • Unexpected empty or malformed body: If status and content type look right, inspect the exact body and compare it with the API’s documented response contract.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

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.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.