I am using google spread-sheet as a database for my application. I want that spreadsheet data to return as a JSON response like GET API. I have written the below code for getting the response.
function doGet(request){
// Open Google Sheet using ID
var sheet = SpreadsheetApp.openById("sheetid");
// Get all values in active sheet
var values = sheet.getActiveSheet().getDataRange().getValues();
var data = [];
for (var i = 1; i <= values.length-1; i++) {
var row = values[i];
var feedback = {};
feedback['timestamp'] = row[1];
feedback['name'] = row[2];
feedback['designation'] = row[3];
feedback['blood_group'] = row[4];
data.push(feedback);
}
return ContentService
.createTextOutput(JSON.stringify(data))
.setMimeType(ContentService.MimeType.JSON);
}
I want my response like this :
[{
"timestamp": "2020-08-03T12:43:38.662Z",
"name": "Mehedi Hasan",
"designation": "developer",
"blood_group": "o-"
}]
but, it's giving response like this:
[{
timestamp: "2020-08-03T12:43:38.662Z",
name: "Mehedi Hasan",
designation: "developer",
blood_group: "o-"
}]
It's returning Javascript object not in JSON string even though I have used JSON.stringify() function to convert it. I don't understand if there is any mistake I have done here? Any suggestion will be helpful.