HomeAbout

json

.json()

.json is an asynchronous method that parses a stringified json response body to a Javascript object.

Because json() method is an asynchronous method, if you don't await the response, it returns an unresolved Promise object.

fetch('https://example.org/products.json') .then(response => response.json()) // not async code // callback is executed after fulfillment // returns Promise wrapped data to next .then chain .then(data => { // another fulfilled Promise console.log(data) })

Alternative:

const response = await fetch('https://example.org/products.json'); const data = await response.json(); // is async
AboutContact