Skip to main content
URL.prototype.toJSON - node__url.d.ts - Node documentation
method URL.prototype.toJSON

Usage in Deno

```typescript import { URL } from "node:node__url.d.ts"; ```
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()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify). ```js 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