title: How to Loop through JSON data
body: <p>I have below JSON data extracted from YQL(google search page).
  I'm trying to loop through this data(using below code but its not helping) and get each key and its value. Please suggest, how can I get the required key and its value.</p>
  
  <p>Thanks.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function getObjects(obj, key, val) {
      var objects = [];
      for (var i in obj) {
          if (!obj.hasOwnProperty(i)) continue;
          if (typeof obj[i] == 'object') {
              objects = objects.concat(getObjects(obj[i], key, val));
          } else if (i == key &amp;&amp; obj[key] == val) {
              objects.push(obj);
          }
      }
      return objects;
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code> {
     "body": {
       "bgcolor": "#fff",
       "script": [
         "(function(){var src='/images/nav_logo199.png';})();"
       ],
       "div": [{
         "id": "mngb",
         "div": {
           "id": "gb",
           "script": [
             "window.gbar&amp;&amp;gbar.elp&amp;&amp;gbar.elp()"
           ],
           "div": [{
             "id": "gbw",
             "div": [{
               "id": "gbz",
               "span": {
                 "class": "gbtcb"
               },
               "ol": {
                 "class": "gbtc",
                 "id": "gbzc",
                 "li": [{
                   "class": "gbt",
                   "a": {
                     "class": "gbzt",
                     "id": "gb_119",
                     "span": [{
                       "class": "gbtb2"
                     }, {
                       "class": "gbts",
                       "content": "Google+"
                     }]
                   }
                 }, {
                   "class": "gbt",
                   "a": {
                     "class": "gbzt gbz0l gbp1",
                     "id": "gb_1",
                     "span": [{
                       "class": "gbtb2"
                     }, {
                       "class": "gbts",
                       "content": "Search"
                     }]
                   }
                 }, {
                   "class": "gbt",
                   "a": {
                     "id": "gb_2",
                     "span": [{
                       "class": "gbtb2"
                     }, {
                       "content": "Images"
                     }]
                   }
                 }, {
                   "class": "gbt",
                   "a": {
                     "id": "gb_8",
                     "span": [{
                       "class": "gbtb2"
                     }, {
                       "content": "Maps"
                     }]
                   }
                 }, {
                   "class": "gbt",
                   "a": {
                     "id": "gb_78",
                     "span": [{
                       "class": "gbtb2"
                     }, {
                       "class": "gbts",
                       "content": "Play"
                     }]
                   }
                 }, {
                   "class": "gbt",
                   "a": {
                     "id": "gb_36",
                     "span": [{
                       "class": "gbtb2"
                     }, {
                       "class": "gbts",
                       "content": "YouTube"
                     }]
                   }
                 }, {
                   "class": "gbt",
                   "a": {
                     "id": "gb_5",
                     "span": [{
                       "class": "gbtb2"
                     }, {
                       "class": "gbts",
                       "content": "News"
                     }]
                   }
                 }, {
                   "class": "gbt",
                   "a": {
                     "id": "gb_23",
                     "span": [{
                       "class": "gbtb2"
                     }, {
                       "class": "gbts",
                       "content": "Gmail"
                     }]
                   }
                 }, {
                   "class": "gbt",
                   "a": {
                     "aria-haspopup": "true",
                     "aria-owns": "gbd",
                     "class": "gbgt",
                     "id": "gbztm",
                     "span": [{
                       "class": "gbtb2"
                     }, {
                       "class": "gbts gbtsa",
                       "id": "gbztms",
                       "span": [{
                         "id": "gbztms1",
                         "content": "More"
                       }, {
                         "class": "gbma"
                       }]
                     }]
                   },
                   "div": {
                     "aria-owner": "gbztm",
                     "class": "gbm",
                     "id": "gbd",
                     "div": {
                       "class": "gbmc gbsb gbsbis",
                       "id": "gbmmb",
                       "ol": {
                         "class": "gbmcc gbsbic",
                         "id": "gbmm",
                         "li": [{
                           "class": "gbmtc",
                           "a": {
                             "class": "gbmt",
                             "content": "Drive"
                           }
                         }, {
                           "class": "gbmtc",
                           "a": {
                             "class": "gbmt",
                             "content": "Calendar"
                           }
                         }, {
                           "class": "gbmtc",
                           "a": {
                             "class": "gbmt",
                             "content": "Translate"
                           }
                         }, {
                           "class": "gbmtc",
                           "a": {
                             "class": "gbmt",
                             "content": "Books"
                           }
                         }, {
                           "class": "gbmtc",
                           "a": {
                             "class": "gbmt",
                             "content": "Blogger"
                           }
                         }, {
                           "class": "gbmtc",
                           "a": {
                             "class": "gbmt",
                             "content": "Photos"
                           }
                         }, {
                           "class": "gbmtc",
                           "a": {
                             "class": "gbmt",
                             "content": "Docs"
                           }
                         }, {
                           "class": "gbmtc",
                           "div": {
                             "class": "gbmt gbmh"
                           }
                         }, {
                           "class": "gbmtc",
                           "a": {
                             "class": "gbmt",
                             "content": "Even more »"
                           }
                         }]
                       },
                       "div": [{
                         "class": "gbsbt"
                       }, {
                         "class": "gbsbb"
                       }]
                     }
                   }
                 }]
               }
             }, {
               "id": "gbg",
               "h2": {
                 "class": "gbxx",
                 "content": "Account Options"
               },
               "span": {
                 "class": "gbtcb"
               },
               "ol": {
                 "class": "gbtc",
                 "li": [{
                   "class": "gbt",
                   "a": {
                     "class": "gbgt",
                     "id": "gb_70",
                     "target": "_top",
                     "span": [{
                       "class": "gbtb2"
                     }, {
                       "class": "gbts",
                       "id": "gbgs4",
                       "span": {
                         "id": "gbi4s1",
                         "content": "Sign in"
                       }
                     }]
                   }
                 }, {
                   "class": "gbt gbtb",
                   "span": {
                     "class": "gbts"
                   }
                 }, {
                   "class": "gbt",
                   "a": {
                     "aria-haspopup": "true",
                     "aria-owns": "gbd5",
                     "class": "gbgt",
                     "id": "gbg5",
                     "title": "Options",
                     "span": [{
                       "class": "gbtb2"
                     }, {
                       "class": "gbts",
                       "id": "gbgs5",
                       "span": {
                         "id": "gbi5"
                       }
                     }]
                   },
                   "div": {
                     "aria-owner": "gbg5",
                     "class": "gbm",
                     "id": "gbd5",
                     "div": {
                       "class": "gbmc",
                       "ol": {
                         "class": "gbmcc",
                         "id": "gbom",
                         "li": [{
                           "class": "gbkc gbmtc",
                           "a": {
                             "class": "gbmt",
                             "content": "Search settings"
                           }
                         }, {
                           "class": "gbmtc",
                           "div": {
                             "class": "gbmt gbmh"
                           }
                         }, {
                           "class": "gbkp gbmtc",
                           "a": {
                             "class": "gbmt",
                             "content": "Web History"
                           }
                         }]
                       }
                     }
                   }
                 }]
               }
             }]
           }, {
             "id": "gbx3"
           }, {
             "id": "gbx4"
           }]
         }
       }, {
         "id": "xjsd"
       }, {
         "data-jiis": "bp",
         "id": "xjsi",
       }],
       "center": {
         "br": {
           "clear": "all",
           "id": "lgpd"
         },
         "div": [{
           "id": "lga",
           "div": {
             "style": "padding:28px 0 3px",
             "div": {
               "align": "left",
               "id": "hplogo",
               "onload": "window.lol&amp;&amp;lol()",
               "title": "Google",
               "div": {
                 "nowrap": "",
                 "content": "India"
               }
             }
           },
           "br": null
         }, {
           "id": "gac_scont"
         }, {
           "style": "font-size:83%;min-height:3.5em",
           "br": null,
           "div": {
             "id": "als",
             "div": {
               "id": "_eEe",
               "a": [{
  
                 "content": "हिन्दी"
               }, {
  
                 "content": "বাংলা"
               }],
               "content": "Google.co.in offered in:                  "
             }
           }
         }],
         "form": {
           "action": "/search",
           "name": "f",
           "table": {
             "cellpadding": "0",
             "cellspacing": "0",
             "tbody": {
               "tr": {
                 "valign": "top",
                 "td": [{
                   "width": "25%",
                   "content": " "
                 }, {
                   "align": "center",
                   "nowrap": "",
                   "input": [{
                     "name": "hl",
                     "type": "hidden",
                     "value": "en-IN"
                   }, {
                     "name": "source",
                     "type": "hidden",
                     "value": "hp"
                   }, {
                     "name": "biw",
                     "type": "hidden"
                   }, {
                     "name": "bih",
                     "type": "hidden"
                   }],
                   "div": {
                     "class": "ds",
                     "style": "height:32px;margin:4px 0",
                     "input": {
                       "autocomplete": "off",
                       "class": "lst",
                       "value": ""
                     }
                   },
                   "br": {
                     "style": "line-height:0"
                   },
                   "span": [{
                     "class": "ds",
                     "span": {
                       "class": "lsbb",
                       "input": {
                         "class": "lsb",
                         "name": "btnG",
                         "type": "submit",
                         "value": "Google Search"
                       }
                     }
                   }, {
                     "class": "ds",
                     "span": {
                       "class": "lsbb",
                       "input": {
                         "class": "lsb",
                         "name": "btnI",
                         "onclick": "if(this.form.q.value)this.checked=1; else top.location='/doodles/'",
                         "type": "submit"
                       }
                     }
                   }]
                 }, {
                   "align": "left",
                   "class": "fl sblc",
                   "nowrap": "",
                   "width": "25%",
                   "a": [{
  
                     "content": "Advanced search"
                   }, {
  
                     "content": "Language tools"
                   }]
                 }]
               }
             }
           },
           "input": {
             "id": "gbv",
             "name": "gbv",
             "type": "hidden",
             "value": "1"
           },
           "script": "(function(){var a,b=\"1\";})();"
         },
         "span": {
           "id": "footer",
           "div": {
             "style": "font-size:10pt",
             "div": {
               "id": "fll",
               "style": "margin:19px auto;text-align:center",
               "a": [{
  
                 "content": "Advertising Programs"
               }, {
  
                 "content": "Business Solutions"
               }, {
  
                 "rel": "publisher",
                 "content": "+Google"
               }, {
                 "content": "About Google"
               }, {
                 "id": "fehl",
                 "content": "Google.com"
               }]
             }
           },
           "p": {
             "style": "color:#767676;font-size:8pt",
             "a": [{
               "content": "Privacy"
             }, {
               "content": "Terms"
             }],
             "content": "© 2015"
           }
         }
       }
     }
   }</code></pre>
  </div>
  </div>
  </p>