This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
The toJSON() method of the PushSubscription interface is a standard serializer: it returns a JSON representation of the subscription properties, providing a useful shortcut.
Syntax
โmySubscription = subscription.toJSON()
Parameters
None.
Returns
A JSON object. It currently only contains the subscription endpoint, as an endpoint member.
Example
navigator.serviceWorker.ready.then(function(reg) {
reg.pushManager.getSubscription().then(function(subscription) {
var mySubscription = subscription.toJSON();
// do something with subscription details
})
});
Specifications
| Specification | Status | Comment |
|---|---|---|
| Push API The definition of 'PushSubscription: toJSON' in that specification. |
Working Draft |
Browser compatibility
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
toJSON() | Chrome Full support 42 | Edge Full support 17 | Firefox Full support 46 | IE No support No | Opera Full support Yes | Safari No support No | WebView Android No support No | Chrome Android Full support 50 | Firefox Android Full support 48 | Opera Android Full support Yes | Safari iOS No support No | Samsung Internet Android Full support 5.0 |
Legend
- Full support
- Full support
- No support
- No support
