W3cubDocs

/Web APIs

ReportBody: toJSON() method

The toJSON() method of the ReportBody interface is a serializer, and returns a JSON representation of the ReportBody object.

Syntax

js

toJSON()

Parameters

None.

Return value

A JSON object that is the serialization of the ReportBody object.

Examples

In this example we create a new ReportingObserver to observe intervention reports, then return a JSON representation of the first entry. The report, and therefore the JSON object returned will be an instance of InterventionReportBody which inherits from ReportBody.

js

const options = {
  types: ["intervention"],
  buffered: true,
};

const observer = new ReportingObserver(([firstReport], observer) => {
  console.log(firstReport.toJSON());
}, options);

Specifications

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
toJSON 69 79 No No 56 16.4 69 69 No 48 16.4 10.0

© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/ReportBody/toJSON