W3cubDocs

/Web APIs

ReportBody: toJSON() method

Note: This feature is available in Web Workers.

Deprecated: This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see the compatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.

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

Syntax

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.

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

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

Specifications

This feature does not appear to be defined in any specification.>

Browser compatibility

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

© 2005–2025 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