PerformanceTimingConfidence: toJSON() method

The toJSON() method of the PerformanceTimingConfidence interface is a serializer that returns a JSON representation of the PerformanceTimingConfidence object.

Syntax

js
toJSON()

Parameters

None.

Return value

A JSON object that is the serialization of the PerformanceTimingConfidence object.

Examples

Using the toJSON method

This example uses a PerformanceObserver to retrieve a JSON serialization of the confidence data for observed PerformanceNavigationTiming entries.

js
const observer = new PerformanceObserver((list) => {
  list.getEntries().forEach((entry) => {
    console.log(entry.confidence.toJSON());
  });
});

observer.observe({ type: "navigation", buffered: true });

This would log a JSON object like so:

json
{
  "randomizedTriggerRate": 0.4994798,
  "value": "high"
}

To get a JSON string, you can use JSON.stringify(entry) directly; it will call toJSON() automatically.

Specifications

Specification
Navigation Timing Level 2
# dom-performancetimingconfidence-tojson

Browser compatibility

See also