Open In App
Related Articles

JQuery | parseJSON() method

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

This parseJSON() method in jQuery takes a well-formed JSON string and returns the resulting JavaScript value.

Syntax:

jQuery.parseJSON( json )

Parameters: The parseXML() method accepts only one parameter that is mentioned above and described below:

  • json: This parameter is the well-formed JSON string to be parsed.

Return Value:

  • It returns the following:
  • String
  • Number
  • Object
  • Array
  • Boolean

Example 1: In this example, we are using the above-explained approach.

html

<!DOCTYPE html>
<html>
 
<head>
    <meta charset="utf-8">
    <title>JQuery | parseJSON() method</title>
    <script src=
 
    </script>
    <style>
        #a {
            color: blue;
        }
 
        #b {
            color: red;
        }
 
        h1 {
            color: green;
        }
 
        body {
            text-align: center;
        }
    </style>
</head>
 
<body>
    <h1>
        GeeksForGeeks
    </h1>
 
    <h3>JQuery | parseJSON() method</h3>
    <b id="a"></b>
 
    <script>
        let txt = '{"name":"John", "age":30, "city":"New York"}'
        let obj = jQuery.parseJSON(txt);
        document.getElementById("a").innerHTML =
            "Object Name : " + obj.name +
            "<br> Object Age : " + obj.age;
    </script>
</body>
 
</html>

                    

Output:

Example 2: In this example, we are using the above-explained approach.

html

<!DOCTYPE html>
<html>
 
<head>
    <meta charset="utf-8">
    <title>JQuery | parseJSON() method</title>
    <script src=
    </script>
 
</head>
 
<body style="text-align:center;">
 
    <h1 style="color: green">
        GeeksForGeeks
    </h1>
 
    <h3>JQuery | parseJSON() method</h3>
    <button onclick="gfg()">
        Click
    </button>
 
    <script>
        function gfg() {
            let txt = '{"name":"Shubham Singh", "age":21, "Cars":"ABC" }'
            let obj = jQuery.parseJSON(txt);
            alert(obj.name === "ABC");
        }
    </script>
</body>
 
</html>

                    

Output:

jquery-52



Last Updated : 11 Jul, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads