files/en-us/web/api/reportbody/tojson/index.md
{{APIRef("Reporting API")}}{{AvailableInWorkers}}{{deprecated_header}}
The toJSON() method of the {{domxref("ReportBody")}} interface is a serializer, and returns a JSON representation of the ReportBody object.
toJSON()
None.
A JSON object that is the serialization of the {{domxref("ReportBody")}} object.
In this example we create a new {{domxref("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 {{domxref("InterventionReportBody")}} which inherits from ReportBody.
const options = {
types: ["intervention"],
buffered: true,
};
const observer = new ReportingObserver(([firstReport], observer) => {
console.log(firstReport.toJSON());
}, options);
{{Specifications}}
{{Compat}}