How to Convert JS Object to JSON String
JSON.stringify()
You can use the JSON.stringify() method to easily convert a JavaScript object a JSON string.
Let's take a look at the following example to see how this basically works:
script> // Sample JS object var obj = {name: "Martin", age: 30, country: "United States"}; // Converting JS object to JSON string var json = JSON.stringify(obj); console.log(json); // Prints: {"name":"Martin","age":30,"country":"United States"} </script>
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Use the
JSON.stringify()MethodYou can use the
JSON.stringify()method to easily convert a JavaScript object a JSON string.Let's take a look at the following example to see how this basically works:
need an explanation for this answer? contact us directly to get an explanation for this answer