Web/API/PushSubscription/toJSON

From Get docs

This is an experimental technologyCheck 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 APIThe definition of 'PushSubscription: toJSON' in that specification. Working Draft  

Browser compatibility

Update compatibility data on GitHub

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
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