Web APIs

Response.json() static

Try the free JavaScript compiler

Creates a Response whose body is JSON serialization of the supplied value. Unlike response.json(), this static method constructs a response.

Formal Syntax & Structure

javascript syntaxjavascript
Response.json(data, init?)

Parameters & Attributes

NameTypeDescription
dataunknownJSON-serializable data.
initResponseInitOptional response status, headers and status text.

Return Value

Response

New JSON response.

Working Example

Example Snippetjavascript
(async()=>{const r=Response.json({id:3},{status:201}); console.log(r.status,r.headers.get("content-type"),(await r.json()).id);})()
JavaScript Reference