PushSubscription.toJSON()

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 (see serializer listed in the WebIDL)' in that specification.
Working Draft Initial definition.

Browser compatibility

FeatureChromeEdgeFirefoxInternet ExplorerOperaSafari
Basic support42 ? ? No ? ?
FeatureAndroid webviewChrome for AndroidEdge mobileFirefox for AndroidOpera AndroidiOS SafariSamsung Internet
Basic support No50 ? ? ? ?5.0

Document Tags and Contributors

 Contributors to this page: fscholz, chrisdavidmills, kitcambridge
 Last updated by: fscholz,