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

Specification
Reporting API
# dom-reportbody-tojson

Browser compatibility

BCD tables only load in the browser