JQuery | parseJSON() method

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:



filter_none

edit
close

play_arrow

link
brightness_4
code

<!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>                                                                

chevron_right


Output:

Example 2: .

filter_none

edit
close

play_arrow

link
brightness_4
code

<!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>                    

chevron_right


Output:
Before Click:

After Click:




My Personal Notes arrow_drop_up

Small things always make you to think big

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.