Performance: toJSON() method

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since April 2021.

Note: This feature is available in Web Workers.

The toJSON() method of the Performance interface is a serializer; it returns a JSON representation of the Performance object.

Syntax

js
toJSON()

Parameters

None.

Return value

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

The returned JSON doesn't contain the eventCounts property because it is of type EventCounts, which doesn't provide a toJSON() operation.

Note: The JSON object contains the serialization of the deprecated performance.timing and performance.navigation properties. To get a JSON representation of the newer PerformanceNavigationTiming interface, call PerformanceNavigationTiming.toJSON() instead.

Examples

Using the toJSON method

In this example, calling performance.toJSON() returns a JSON representation of the Performance object.

js
performance.toJSON();

This would log a JSON object like so:

json
{
  "timeOrigin": 1668077531367.4,
  "timing": {
    "connectStart": 1668077531372,
    "navigationStart": 1668077531367,
    "secureConnectionStart": 0,
    "fetchStart": 1668077531372,
    "domContentLoadedEventStart": 1668077531580,
    "responseStart": 1668077531372,
    "domInteractive": 1668077531524,
    "domainLookupEnd": 1668077531372,
    "responseEnd": 1668077531500,
    "redirectStart": 0,
    "requestStart": 1668077531372,
    "unloadEventEnd": 0,
    "unloadEventStart": 0,
    "domLoading": 1668077531512,
    "domComplete": 1668077531585,
    "domainLookupStart": 1668077531372,
    "loadEventStart": 1668077531585,
    "domContentLoadedEventEnd": 1668077531580,
    "loadEventEnd": 1668077531585,
    "redirectEnd": 0,
    "connectEnd": 1668077531372
  },
  "navigation": {
    "type": 0,
    "redirectCount": 0
  }
}

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

Specifications

Specification
High Resolution Time
# dom-performance-tojson

Browser compatibility

desktop mobile server
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Bun
Deno
Node.js
toJSON
Chrome – Full support
Chrome 56 (Release date: 2017-01-25)
footnote Full support
Edge – Full support
Edge 12 (Release date: 2015-07-29)
footnote Full support
Firefox – Full support
Firefox 25 (Release date: 2013-10-29)
footnote Full support
Opera – Full support
Opera 43 (Release date: 2017-02-07)
footnote Full support
Safari – Full support
Safari 14.1 (Release date: 2021-04-26)
footnote Full support
Chrome Android – Full support
Chrome Android 56 (Release date: 2017-02-01)
footnote Full support
Firefox for Android – Full support
Firefox for Android 25 (Release date: 2013-10-29)
footnote Full support
Opera Android – Full support
Opera Android 43 (Release date: 2017-09-27)
footnote Full support
Safari on iOS – Full support
Safari on iOS 14.5 (Release date: 2021-04-26)
footnote Full support
Samsung Internet – Full support
Samsung Internet 6 (Release date: 2017-08-23)
footnote Full support
WebView Android – Full support
WebView Android 56 (Release date: 2017-02-01)
footnote Full support
WebView on iOS – Full support
WebView on iOS 14.5 (Release date: 2021-04-26)
footnote Full support
Bun – Full support
Bun 1.0.22 (Release date: 2024-01-10)
footnote Full support
Deno – Full support
Deno 1.22 (Release date: 2022-05-18)
footnote Full support
Node.js – Full support
Node.js 16.1 (Release date: 2021-05-04)
footnote Full support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

See also