UncleCoder.com

UncleCoder.com

Free programming examples and instructions

Convert JSON object to string

Code for how to convert json object to json string

by Athil


Posted on 13 Jul 2017 Category: Javascript Views: 194

Edited on 10 Aug 2017



DEMO

Hi, Here I am going to hot to convert JSON object to JSON string.

Syntax for stringify

JSON.stringify(jsondata);

 

Full Demo Code for stringify

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Demo and Code for Json data to string</title>
    <h1>Demo and Code for Json data to string </h1>
</head>
<body>
    <button onclick ="convertotjson();">Convert to json </button>

    <script>
        function convertotjson()
        {
            var JSONdata = { "name": "alex","age":"18" };
            datastring =  JSON.stringify(JSONdata);
            alert(datastring);
        }

        </script>
</body>
</html>

 



Leave a Comment:


Advertisement