Since March 2023, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.
Note: This feature is available in Web Workers.
The toJSON() method of the PushSubscription interface is a standard serializer: it returns a JSON representation of the subscription properties, providing a useful shortcut.
toJSON()
None.
A JSON object. It contains the subscription endpoint, expirationTime and public keys, as an endpoint member, an expirationTime member and a keys member.
navigator.serviceWorker.ready.then((reg) => {
reg.pushManager.getSubscription().then((subscription) => {
const mySubscription = subscription.toJSON();
// do something with subscription details
});
});
| Specification |
|---|
| Push API> # dom-pushsubscription-tojson> |
| 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 |
42 | 17 | 44 | 29 | 16Notifications are supported on macOS Ventura and later. |
50 | 48 | 37 | 16.4Notifications are supported in web apps saved to the home screen. |
5.0 | No | NoNotifications are supported in web apps saved to the home screen. |
© 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/PushSubscription/toJSON