title: Importing value from JSON array to Google Sheets
body: <p>this may be a syntax question more than anything, but I'm importing JSON into google sheets with the following script:</p>
  
  <pre><code>function IMPORTJSON(url,xpath){
  
    try{
      var res = UrlFetchApp.fetch(url);
      var content = res.getContentText();
      var json = JSON.parse(content);
  
      var patharray = xpath.split("/");
  
      for(var i=0;i&lt;patharray.length;i++){
        json = json[patharray[i]];
      }
  
      if(typeof(json) === "undefined"){
        return "Not available";
      } else if(typeof(json) === "object"){
        var tempArr = [];
  
        for(var obj in json){
          tempArr.push([obj,json[obj]]);
        }
        return tempArr;
      } else if(typeof(json) !== "object") {
        return json;
      }
    }
    catch(err){
        return "Error";  
    }
  
  }
  </code></pre>
  
  <p>And I'm able to get values fine, The syntax for something simple like name from this: <code>"productinfo": { "name":, "url": }</code> is just <code>=IMPORTJSON(urlgoeshere,"productinfo/name")</code>. But I can't figure out how to get a value inside an array. Let's say for example I was trying to get the front image URL from this:</p>
  
  <pre><code>"images": [ {
      "front": "http://front.jpg",
      "back": "http://back.jpg",
      "side": "http://side.jpg"
      } ]
  </code></pre>
  
  <p>I've tried a number of things like <code>"images/front"</code>, <code>"images[0]/front"</code> but am having no luck. Any ideas?</p>