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: toJSON' in that specification.
Working Draft  

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
toJSON()Chrome Full support 42Edge Full support 17Firefox Full support 46IE No support NoOpera Full support YesSafari No support NoWebView Android No support NoChrome Android Full support 50Firefox Android Full support 48Opera Android Full support YesSafari iOS No support NoSamsung Internet Android Full support 5.0

Legend

Full support  
Full support
No support  
No support