Skip to content
Related Articles

Related Articles

JQuery | parseJSON() method
  • Last Updated : 27 Apr, 2020
GeeksforGeeks - Summer Carnival Banner

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:






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

Output:

Example 2: .




<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JQuery | parseJSON() method</title
  
</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(){
            var txt = '{"name":"Shubham Singh", "age":21, "Cars":"ABC" }'
            var obj = jQuery.parseJSON(txt);
            alert( obj.name === "ABC" );
        }
        </script>
</body>
</html>                    

Output:
Before Click:

After Click:

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :