I am working on retrieving data from a Google Spreadsheet using App Script and have set up a DoGet function. Currently, I am getting an array of data but I need it in JSON key-value pairs format.
The table in my Google Sheets is structured as follows:
This is how the DoGet function is currently configured:
function doGet(e) {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var returnData = sheet.getRange('A1:B2').getValues()
return ContentService.createTextOutput(JSON.stringify(returnData))
}
The current output looks like this:
[
["fruit", "vegetable"],
["ABC", "DEF"]
]
However, I actually need the data to be in JSON key:value pairs like this:
{
"fruit": "ABC",
"vegetable": "DEF"
}