CKTIS / JavaScript
Response.json(): creating a JSON response
The static Response.json() method creates a response containing JSON data. Do not confuse it with response.json(), which reads a response body.
Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support
Syntax
Response.json(data[, init])Response.json(data, init) synchronously returns a new Response with a JSON-encoded body. It does not send a network request.
Optional init sets status, statusText, and headers; the default status is 200. Content-Type defaults to application/json unless explicitly supplied. Statuses 204, 205, and 304 forbid a body and therefore cause TypeError.
Do not confuse it with response.json(): that instance method consumes the body and returns a Promise for the parsed value. This is a Fetch Web API, not a feature of a particular ECMAScript edition. Check typeof Response !== "undefined" && typeof Response.json === "function"; availability in Node 24 does not prove browser support.
Examples
(async () => {
const response = Response.json({ name: "Ada" }, { status: 201 });
console.log(response.status);
console.log(response.headers.get("Content-Type"));
const data = await response.json();
console.log(data.name);
})().catch(console.error);Result
201 application/json Ada
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.