WEB TUTORIALS
PRACTICE EXAMPLES
HTML REFERENCES
CSS REFERENCES
PHP REFERENCES
Advertisements

How to Convert JS Object to JSON String

Topic: JavaScript / jQueryPrev|Next

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>

See the tutorial on JavaScript JSON parsing to learn more about encode/decode JSON data.


Related FAQ

Here are some more FAQ related to this topic:

Advertisements
Bootstrap UI Design Templates

Your Feedback:

We would love to hear from you, please drop us a line.