Search code examples
javascriptjsongoogle-fusion-tables

Parsing Google Fusiontable API returned JSON in Javascript


Can someone please shed some light on how to parse this JSON object returned by Google Fusion Tables query APIs in Javascript?

{
 "kind": "fusiontables#sqlresponse",
 "columns": [
  "Name",
  "Function",
  "Culprit"
 ],
 "rows": [
  [
   "Bha3",
   "9, 41",
   "1"
  ],
  [
   "Bha23",
   "7, 26, 56, 57",
   "1"
  ]
 ]
}

I want to extract values Bha3 and Bha23 from this object. But there are no names in "columns" and "rows" objects. So essentially, this is not a JSON object(?) How do I get individual values from rows?


Solution

  • You can access those values by looking up the 2-d array rows

    data.rows[0][0]; //Bha3
    data.rows[1][0]; //Bha23
    

    Where data is your object.

    Demo

    And with simple for loop you can access all values like this