Docs

URL.prototype.toJSON

Returns the URL as a JSON string.

Example

let url = new URL("https://example.com/path?foo=bar")
url.toJSON()
"https://example.com/path?foo=bar"
let url = new URL("https://example.com")
JSON.stringify({url: url})
"{\"url\":\"https://example.com/\"}"
let url = new URL("https://[email protected]:8080/api")
url.toJSON()
"https://[email protected]:8080/api"