Skip to content

Instantly share code, notes, and snippets.

@KartikTalwar
Created January 10, 2017 02:07
Show Gist options
  • Save KartikTalwar/dfee4be5fe4cdf88ff0ff671af32f6c4 to your computer and use it in GitHub Desktop.
Save KartikTalwar/dfee4be5fe4cdf88ff0ff671af32f6c4 to your computer and use it in GitHub Desktop.

Revisions

  1. KartikTalwar created this gist Jan 10, 2017.
    24 changes: 24 additions & 0 deletions google-apps-script-json-parser.gs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    // call this function on a cell via =ImportJSON("http://...") and data will show up verbatim
    function ImportJSON(url) {
    var response = UrlFetchApp.fetch(url);
    var data = JSON.parse(response.getContentText());

    if (!data.length) {
    return [];
    }

    var rows = [];
    var headers = Object.keys(data[0]);

    rows.push(headers);

    for (var i=0; i<data.length; i++) {
    var row = [];
    for (var j=0; j<headers.length; j++) {
    row.push(data[i][headers[j]]);
    }
    rows.push(row);
    }

    return rows;
    }