Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function doGet() {
- //get the data from the spreadsheet into a multidimensional array
- var data = SpreadsheetApp.getActiveSheet().getDataRange().getValues();
- //take the first row of header information and save it into its own array
- var header = data.shift();
- //create an empty array to store our objects after we build them
- var apiData = [];
- data.forEach(function(row) {
- //create an empty object
- var eachObj = {};
- for(var i = 0; i < header.length; i++) {
- //match the keys and values
- eachObj[header[i]] = row[i];
- }
- //add this object to the array
- apiData.push(eachObj);
- });
- //return the array of objects as JSON
- return ContentService.createTextOutput(JSON.stringify(apiData)).setMimeType(ContentService.MimeType.JSON);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement