October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk4 min

How to Read JSON from a Puppeteer Response

Use Puppeteer’s response.json() to parse an HTTPResponse body, with separate checks for HTTP status, navigation responses, and browser-triggered API calls.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use await response.json() to parse the body of a Puppeteer HTTPResponse. Check the HTTP status separately: a response can arrive with a 404 or 500 status and still contain a body, while json() rejects if that body is not valid JSON.

Parse the response body

For a navigation response, page.goto() returns the response for the page’s main resource when one exists. Guard against a missing response, check its status, then parse its JSON body:

As an Amazon Associate I earn from qualifying purchases.

const response = await page.goto('https://example.com/data');

if (!response) {
  throw new Error('Navigation did not provide an HTTP response');
}

console.log('status:', response.status());
if (!response.ok()) {
  throw new Error(`HTTP ${response.status()}: ${response.statusText()}`);
}

const data = await response.json();
console.log(data);

json() returns a promise that resolves to the value represented by the body. That value may be an object, array, string, number, boolean, or null; it is not necessarily an object. Puppeteer documents that parsing throws if the response body cannot be parsed by JSON.parse (HTTPResponse.json()).

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.

Capture JSON from a browser interaction

When a click or other browser action triggers an API request, set up waitForResponse() before triggering the action. Filter by a stable endpoint detail and, where useful, the request method so another request is not mistaken for the one you need:

const responsePromise = page.waitForResponse(response =>
  response.url().includes('/api/items') &&
  response.request().method() === 'GET'
);

await page.click('button.load-items');

const response = await responsePromise;
if (!response.ok()) {
  throw new Error(`HTTP ${response.status()}: ${response.statusText()}`);
}

const items = await response.json();
console.log(items);

waitForResponse() accepts a URL or predicate, with timeout and cancellation options. Match the request that matters rather than assuming the next response belongs to the action; pages commonly make unrelated requests at the same time. See the Page.waitForResponse() reference.

Choose the right response source

Situation Use Important check
You want the page’s main navigation resource page.goto(url) It may return null, including navigation to about:blank or the same URL with only a different hash. Guard before calling response methods.
You want an API request caused by an interaction page.waitForResponse(urlOrPredicate) Register the wait before the click or action, and narrow the match to the intended request.

The relevant navigation and response behavior is documented in Puppeteer’s Page API.

Check status independently from JSON parsing

response.ok() is true only for HTTP status codes from 200 through 299. It tells you about status, not whether the body is valid JSON. A 404 or 503 can still be a completed HTTP response, and its body may be JSON, HTML, or another format. Decide how your code should handle non-2xx statuses before relying on the payload. Puppeteer documents status(), statusText(), ok(), and response headers in its HTTPResponse API.

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

Troubleshoot parsing and capture failures

response.json() throws

The body is not parseable JSON. Inspect the raw body and metadata to see what the server actually returned:

console.log('url:', response.url());
console.log('status:', response.status(), response.statusText());
console.log('headers:', response.headers());
console.log('body:', await response.text());

This often reveals an HTML error page or a different payload than expected. text() returns UTF-8 text and can itself throw if the content is not UTF-8. The response methods are described in the HTTPResponse reference.

The captured response is unrelated

Refine the waitForResponse() predicate using the endpoint, method, or another known property, and create the wait before the action. The page may issue multiple requests in response to a click.

The server returns 404 or 500

Check status() or ok() before treating the payload as success data. The body might be a JSON error object or an HTML error page; status alone does not identify its format.

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

The request fails instead of completing

A network failure is different from receiving an HTTP error response. Puppeteer distinguishes requestfailed from requestfinished; inspect the lifecycle of the specific request rather than assuming JSON parsing caused the failure. See the HTTPRequest API.

page.goto() returns null

Some navigations do not produce a response object, including about:blank and a same-URL navigation that changes only the hash. Guard the return value before calling status() or json().

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

Or skip the browser setup

If your goal is a screenshot or PDF rather than parsing an API response, ScreenshotNeo provides a website screenshot API and MCP server. A single GET request captures a URL; its API also supports PDF output. For example, save a screenshot as WebP:

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

See the ScreenshotNeo API documentation for request options. Cookie banners, newsletter popups, and chat widgets are removed before capture by default, and each step can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed; response headers identify the page verdict and billing status. An MCP server exposes screenshot tools for Claude, Cursor, and other MCP clients. The Free plan includes 1,000 screenshots per month with no card required; paid plans start at $5 for 3,000 shots.

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

Sign up for ScreenshotNeo’s free plan to get 1,000 screenshots a month with no card.

Frequently Asked Questions

Is response.json() the same as JSON.stringify()?

No. response.json() parses a response body into a JavaScript value; JSON.stringify() serializes a JavaScript value into JSON text.

Can I use this method on a browser-side fetch() response?

The Fetch API has its own Response.json() method, but it belongs to the browser Fetch API and execution context, not Puppeteer’s HTTPResponse object.

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.

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

Leave a Reply

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

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

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
PC Slower Than It Used to Be?Free scan - under a minute

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.