Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Convert JavaScript Object to JSON String</title> </head> <body> <script> // Sample JS object var obj = {name: "Martin", age: 30, country: "United States"}; // Converting JS object to JSON string var json = JSON.stringify(obj); document.write(json); // Prints: {"name":"Martin","age":30,"country":"United States"} </script> </body> </html>