The toJSON() method of the PushSubscription interface is a standard serializer: it returns a JSON representation of the subscription properties, providing a useful shortcut.
The toJSON() method of the PushSubscription interface is a standard serializer: it returns a JSON representation of the subscription properties, providing a useful shortcut.
js
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.
js
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 | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
toJSON |
42 | 17 | 44 | No | 29 | 16Supported on macOS 13 and later |
No | 50 | 48 | 37 | 16.4 | 5.0 |
© 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/PushSubscription/toJSON