W3cubDocs

/Web APIs

PerformanceEntry: toJSON() method

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

Syntax

js

toJSON()

Parameters

None.

Return value

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

Examples

Using the toJSON method

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

js

performance.mark("debug-marker", {
  detail: "debugging-marker-123",
});

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

observer.observe({ entryTypes: ["mark"] });

This would log a JSON object like so:

json

{
  "name": "debug-marker",
  "entryType": "mark",
  "startTime": 158361,
  "duration": 0
}

Note that it doesn't contain PerformanceMark's detail property.

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

Specifications

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
toJSON 45 16 35 No 32 11 45 45 35 32 11 5.0

See also

© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/PerformanceEntry/toJSON