Reputation: 139
I am able to parse data from google sheet api v4. Here is retrieve sheet data.
Sample:
https://sheets.googleapis.com/v4/spreadsheets/1vW-N2WRchAmxd8-isEx4oPpJourPsIIavqfvT_Nbtzw/values/Master?key=AIzaSyAwaXGDfOOdUX-YaGIn0S8Q7ae-ONC_cLs
But i want to retrive these data in below json format
{"values":[
{"Timestamp":"2021-03-09", "Student ID-Name":"", "Umail":"[email protected]", "Geoloc-Latitude":"", "Geoloc-Longitude":"", "Subject-Code":"PHY4101"},
{"Timestamp":"2021-03-09", "Student ID-Name":"", "Umail":"[email protected]", "Geoloc-Latitude":"", "Geoloc-Longitude":"", "Subject-Code":"MATH4103"},
{"Timestamp":"2021-04-13", "Student ID-Name":"", "Umail":"[email protected]", "Geoloc-Latitude":"", "Geoloc-Longitude":"", "Subject-Code":"HUM4105"}
]}
If anyone solve this, it's huge help for me...TIA
Upvotes: 0
Views: 3394
Reputation: 15328
Try
function table2json() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Master');
var [headers, ...rows] = sheet.getDataRange().getValues();
var data = {}
var items = []
rows.forEach(function(r) {
var obj={}
r.forEach(function (c, j) {
obj[headers[j]] = c
})
items.push(obj)
})
data['values'] = items
Logger.log(JSON.stringify(data))
}
you will get a json that represents your datarange
Upvotes: 1
Reputation: 1047
you can use this https://opensheet.vercel.app/id/range
https://sheets.googleapis.com/v4/spreadsheets/1vW-N2WRchAmxd8-isEx4oPpJourPsIIavqfvT_Nbtzw/values/Master?key=AIzaSyAwaXGDfOOdUX-YaGIn0S8Q7ae-ONC_cLs
you can get the ID and range.1vW-N2WRchAmxd8-isEx4oPpJourPsIIavqfvT_Nbtzw
https://opensheet.vercel.app/1vW-N2WRchAmxd8-isEx4oPpJourPsIIavqfvT_Nbtzw/Master!A1:Z14989
Upvotes: 4
Reputation: 1
Step 1: Fire up Google Spreadsheet and enter your data. Generate a shareable link and switch to "Anyone with the link on the internet can View." Copy the link to your clipboard. Step 3: Type [sheet.best] on the browser and click on the +Connect button. Step 4: On the Connection URL section, paste the Spreadsheet URL.
#JSON #Google Sheet #API
Specify the origin into Google Spreadsheet. Step 5: Tap on the Connect option, and there you go! A brand new REST API in the Connection URL. Step 6: Copy the API or Connection URL into your clipboard. Step 7: Paste it on the browser, and experience the spreadsheet data in JSON format!
Upvotes: 0