MDN self-hosted library · e01.org

URL: toJSON() method

Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.

js
const url = new URL(
  "https://developer.mozilla.org/en-US/docs/Web/API/URL/toString",
);

const json = url.toJSON();
console.log(json); // https://developer.mozilla.org/en-US/docs/Web/API/URL/toString
console.log(typeof json); // "string"
js
console.log(JSON.stringify(url));