Q:

How to Convert JS Object to JSON String

0

How to Convert JS Object to JSON String

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Use the JSON.stringify() Method

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>

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

JavaScript / jQuery Frequently Asked Questions

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
How to Add New Elements at the Beginning of an Arr... >>
<< How to Generate a Timestamp in JavaScript...