![]() |
VOOZH | about |
The URL.toJSON() method in Node.js converts a URL object into a JSON-friendly string representation. It enables URL objects to be serialized automatically, making them easier to store and exchange in structured data formats.
JSON.stringify().Syntax
url.toJSON()where,
URL constructor. Return Value: Returns the serialized URL as a string. The returned value is equivalent to url.href and url.toString().
Example 1:
Output:
[
"https://www.geeksforgeeks.org//",
"https://www.google.com//",
"https://mygeeks.com//"
]
Example 2:
Output:
[
"https://www.geeksforgeeks.org//",
"https://write.geeksforgeeks.org///",
"https://www.practice.geeksforgeeks.org/",
"https://www.demo.geeksforgeeks.org/",
"https://write.geeksforgeeks.org///"
]
Note: The above program will compile and run by using the node index.js command.
URL.toJSON() Method