-
-
Save varun-raj/5350595a730a62ca1954 to your computer and use it in GitHub Desktop.
function pullJSON() { | |
var ss = SpreadsheetApp.getActiveSpreadsheet(); | |
var sheets = ss.getSheets(); | |
var sheet = ss.getActiveSheet(); | |
var url="http://example.com/feeds?type=json"; // Paste your JSON URL here | |
var response = UrlFetchApp.fetch(url); // get feed | |
var dataAll = JSON.parse(response.getContentText()); // | |
var dataSet = dataAll; | |
var rows = [], | |
data; | |
for (i = 0; i < dataSet.length; i++) { | |
data = dataSet[i]; | |
rows.push([data.id, data.name,data.email]); //your JSON entities here | |
} | |
dataRange = sheet.getRange(1, 1, rows.length, 3); // 3 Denotes total number of entites | |
dataRange.setValues(rows); | |
} |
@varun-raj, your code is not working in my case
I am trying to grab the data from a webhook(data is in JSON) and post it to my Google sheet.
In the code, the first line won't work for me as I am deploying the script as a web app(which would catch the webhook)
var response = UrlFetchApp.fetch(url); // get feed
var dataAll = JSON.parse(response.getContentText()); //
var dataSet = dataAll;
In place of line 2 I am trying with these but I have not got any results.
//1// var myObj = e.postData.getDataAsString();
//2//var myObj2=JSON.parse(e.getContentText());
//3// var myObj3= JSON.parse(e);
None of these is giving me any results.(sheet is blank)
but when i use this :
sheet.getRange(lastRow+1, 1).setValue(JSON.stringify(e));
I am getting the raw data into a single cell.
This the page containing references of what is coming as the webhook payload:
https://help.shopify.com/en/api/reference/events/webhook
Could you please help me?
This is great and useful - any tips on bringing in a lot of data? I've got ~50k lines of data w 8 data points and I get only very slow responses and timeouts. Thanks!
@varun-raj, how do i parse a JSON like this? Your code doesn't work with this JSON. Can you help urgently?