The toJSON()
method of the URL
interface returns a DOMString
containing the whole URL. It returns the same string as the href
property.
This method is supposed to only be invoked by the JSON.stringify()
method.
const url = new URL("https://developer.mozilla.org/en-US/docs/Web/API/URL/toJSON"); const obj = {key: url}; console.log(JSON.stringify(obj)); // logs '{"key": "https://developer.mozilla.org/en-US/docs/Web/API/URL/toJSON"}'
Specification | Status | Comment |
---|---|---|
URL The definition of 'toJSON()' in that specification. | Living Standard | Initial definition. |
Desktop | ||||||
---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | |
Basic support | ? | 17 | 54 | ? | ? | ? |
Mobile | |||||||
---|---|---|---|---|---|---|---|
Android webview | Chrome for Android | Edge Mobile | Firefox for Android | Opera for Android | iOS Safari | Samsung Internet | |
Basic support | ? | ? | ? | 54 | ? | ? | ? |
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/URL/toJSON