Forked from KartikTalwar/google-apps-script-json-parser.gs
Created
February 24, 2021 20:57
-
-
Save emonteiroD1/32e7d4abaad826f0aeca5e7074f56bd5 to your computer and use it in GitHub Desktop.
Google Apps Script JSON Parser
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment