Back to Content

InterventionReportBody: toJSON() method

files/en-us/web/api/interventionreportbody/tojson/index.md

latest884 B
Original Source

{{APIRef("Reporting API")}}{{AvailableInWorkers}}{{SeeCompatTable}}

The toJSON() method of the {{domxref("InterventionReportBody")}} interface is a serializer, and returns a JSON representation of the InterventionReportBody object.

Syntax

js-nolint
toJSON()

Parameters

None.

Return value

A JSON object that is the serialization of the {{domxref("InterventionReportBody")}} object.

Examples

In this example we create a new {{domxref("ReportingObserver")}} to observe intervention reports, then return a JSON representation of the first entry.

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

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

Specifications

{{Specifications}}

Browser compatibility

{{Compat}}