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 AndroidEdge MobileFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
<code.tojson()< code=""></code.tojson()<>Chrome Full support 42Edge Full support 17Firefox Full support 46IE No support NoOpera ? Safari No support NoWebView Android No support NoChrome Android Full support 50Edge Mobile ? Firefox Android Full support 46Opera Android ? Safari iOS No support NoSamsung Internet Android Full support 5.0

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown

Document Tags and Contributors

Last updated by: mdnwebdocs-bot,