ReportBody: toJSON() method

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Note: This feature is available in Web Workers.

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

Specification
Reporting API
# dom-reportbody-tojson

Browser compatibility

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
toJSON

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
User must explicitly enable this feature.