MDN Web Docs

Syntax

js

json()

Parameters

None.

Return value

A Promise that resolves to a JavaScript object. This object could be anything that can be represented by JSON — an object, an array, a string, a number…

Exceptions

TypeError

Thrown for one of the following reasons:

SyntaxError

The request body cannot be parsed as JSON.

Examples

js

const obj = { hello: "world" };
const request = new Request("/myEndpoint", {
  method: "POST",
  body: JSON.stringify(obj),
});
request.json().then((data) => {
  // do something with the data sent in the request
});

Specifications

Specification
Fetch
# ref-for-dom-body-json①

Browser compatibility

See also

Help improve MDN

Yes No

Learn how to contribute

This page was last modified on by MDN contributors.

Read the original on developer.mozilla.org ↗