← Back to release summary

Response.json()

Category
Network / Connectivity
Type
Chromium catches up
Status
Enabled by default (Chrome 105)
Intent stage
Shipped

Summary

Improves ergonomics for creating JSON Response objects. The Response constructor allows for creating the body of the response from many types, however it is not possible to directly create a JSON object. The Response.json() static method fills this gap. It returns a Response object with a body consisting the first argument serialized as JSON. The second argument is a ResponseInit option bag as with the Response constructor.

Motivation

Creating a Response object with a body of a JSON object has been harder than the other types supported by Fetch. This change improves the ergonomics of creating a JSON response.

Standards & signals

Explainers: https://docs.google.com/document/d/1dTycWmyxLZNGTBW93fvtf1IQahx-vNwgu94yT1x9K50/edit

View on chromestatus.com