PerformanceNavigation: toJSON() method
Deprecated
Avoid using this feature in new projects.
This feature is supserseded by the PerformanceNavigationTiming API.
This feature may be a candidate for removal from web standards or browsers.>
Consider using the following features instead: Performance or Navigation timing performance entries.>
Warning:
This interface of this property is deprecated in the Navigation Timing Level 2 specification. Please use the PerformanceNavigationTiming
interface instead.
The toJSON() method of the PerformanceNavigation interface returns a JSON-serializable plain object representing the PerformanceNavigation object.
The method is automatically called by JSON.stringify() when a PerformanceNavigation object is encountered during JSON serialization.
Syntax
toJSON()
Parameters
None.
Return value
A JSON-serializable plain object containing the following properties:
Each property's value is copied as-is.
Examples
>Calling toJSON() directly
Calling toJSON() directly on performance.navigation returns a plain object. Its properties have the same values as the corresponding properties of the original object.
const json = performance.navigation.toJSON();
console.log(json); // A plain object
console.log(typeof json); // "object"
console.log(json.type); // Same value as performance.navigation.type
Serializing to a JSON string
In this example, the PerformanceNavigation object is serialized using JSON.stringify(), which calls the toJSON() method automatically.
console.log(JSON.stringify(performance.navigation));
This would log a JSON string like so (formatted for readability):
{
"type": 0,
"redirectCount": 0
}
Specifications
| Specification |
|---|
| Navigation Timing Level 2> # dom-performancenavigation-tojson> |