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": "Peter", "age": 22, "country": "United States"}; // Converting JS object to JSON string var json = JSON.stringify(obj); document.write(json); </script> </body> </html>