Skip to content

JavaScript JSON stringify() Method | object to a JSON string

  • by

Using the JavaScript function JSON stringify(), you can convert it into a string. It required when sending data to a web server the data has to be a string.

JSON.stringify(obj, replacer, space)

Example JavaScript JSON stringify() Method

Simple HTML example code.

<!DOCTYPE html>
<html>
<head>

  <script>

    var obj = { "Name":"John", "Age":50, "City":"New York"};
    var myJSON = JSON.stringify(obj);

    console.log(myJSON)
    console.log(typeof(myJSON))

  </script>

</head>
</html>

Output:

JavaScript JSON stringify() Method

Do comment if you have any doubts or suggestions on this JS JSON function topic.

Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.

OS: Windows 10

Code: HTML 5 Version

Leave a Reply

Your email address will not be published. Required fields are marked *