1 | initial version |
Here is a sample code for iterating through JSON URLs and retrieving data from them in Google Sheets using Apps Script:
function getDataFromJSON() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1");
var urls = ["https://jsonplaceholder.typicode.com/todos/1", "https://jsonplaceholder.typicode.com/todos/2"]; //array of JSON URLs
for(var i = 0; i < urls.length; i++) { //iteration through URLs
var response = UrlFetchApp.fetch(urls[i]); //fetch data from URL
var data = JSON.parse(response.getContentText()); //parse the JSON data
var row = [data.userId, data.id, data.title, data.completed]; //retrieve required data and store in an array
sheet.appendRow(row); //append the data to the sheet
}
}
In this code, we have created an array of JSON URLs (urls
) that we want to retrieve data from. We are iterating through the URLs and fetching the data using the UrlFetchApp
function. We are then parsing the JSON data using the JSON.parse()
function and retrieving the required data. We are storing the data in an array (row
) and appending it to the sheet using the appendRow()
function.
You can modify this code as per your requirement to retrieve data from the JSON URLs and store them in the sheet.