Web APIs
Response.json() static
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
| Name | Type | Description |
|---|---|---|
| data | unknown | JSON-serializable data. |
| init | ResponseInit | Optional 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);})()