phpicoder Dec 14, 2021 Jquery

Hi guys, in this article we will provide an example of how to convert json object objects to string using jquery, in this tutorial we will learn simple examples of how to convert json object to string using jquery. So we make a simple example of how to convert an json object to a string in jquery.

We will Using JSON.stringify() jquery method. this method in javascript allows us to take a JavaScript object or Array and create a JSON string out of it.

Let's look at 2 simple examples that will help you, follow my example below

Example 1: Stringify a JavaScript Array Object

<!DOCTYPE html>
<html>
<head>
    <title>Jquery convert json object to string example - phpicoder.com</title>
</head>
<body>
<script>

    var userObject = {
        id: 101,
        name: "vikramvanaliya",
        email: "phpicoder@gmail.com",
        city: "Ahmedabad",
        country: "India"
    };

    var stringObj = JSON.stringify(userObject);
    console.log(stringObj);

</script>
</body>
</html>
Output:
{"id":101,"name":"vikramvanaliya","email":"phpicoder@gmail.com","city":"Ahmedabad","country":"India"}

Example 2: Stringify a JavaScript Array 

<!DOCTYPE html>
<html>
<head>
    <title>Jquery convert json object to string example - phpicoder.com</title>
</head>
<body>
<script>

    var lngArr = [
        'php',
        'java',
        'python',
        'ios',
        'android'
    ];

    var stringObj = JSON.stringify(lngArr);
    console.log(stringObj);

</script>
</body>
</html>
Output:
["php","java","python","ios","android"]

I hope it can help you...