Search.../

json( )

Reads the response body as JSON.

Description

The json() function reads the body response stream to its completion and parses it as JSON. It returns a Promise that resolves to the response body as a JSON object.

Syntax

function json(): Promise<Object>

json Parameters

This function does not take any parameters.

Returns

Fulfilled - The parsed response body as JSON. Rejected - The errors that caused the rejection.

Return Type:

Promise<Object>

Was this helpful?

Get the response's body as JSON.

Copy Code
1let json = response.json(); // {"key": "some value"}
Get the response's body as JSON and log it to the console.

Copy Code
1fetch(url, {"method": "get"})
2 .then(response => response.json())
3 .then(json => console.log(JSON.stringify(json)));