Skip to main content
URL.prototype.toJSON - url - Node documentation
method URL.prototype.toJSON

Usage in Deno

import { URL } from "node:url";
URL.prototype.toJSON(): string

The toJSON() method on the URL object returns the serialized URL. The value returned is equivalent to that of href and toString.

This method is automatically called when an URL object is serialized with JSON.stringify().

const myURLs = [
  new URL('https://www.example.com'),
  new URL('https://test.example.org'),
];
console.log(JSON.stringify(myURLs));
// Prints ["https://www.example.com/","https://test.example.org/"]

Return Type

string