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.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2021-06-11 11:00:00 +0000
Seen: 14 times
Last updated: Aug 02 '21
Is it possible to update a Google Doc by submitting multiple forms?
How can we bring googlesheets data into a pyspark dataframe?
When running a dataset, Google Collab indicates that the RunTime is disconnected.
Why does the app shut down when switching to the Google Maps section in a Flutter application?
Can you rephrase this query: Google Search Console - Error in locating (404)?
What does "Read timed out" mean in relation to a Batch Request in the Google Calendar API?
What should I do if I have forgotten my account to create a Google cloud bucket?