Creating a web app to return JSON
Now, we will see how to return JSON string instead of HTML content. In the Data
Sheet, add another column named DOB
as shown here:
Create the doGet
function as shown here:
function doGet(){ /* * This spreadsheet may not be active while this function * executes, so you cannot get access to active spreadsheet, * use open by id. * */ var ss = SpreadsheetApp .openById("Replace with this spreadsheet id"); var SheetData = ss.getSheetByName("Data"); var data = SheetData.getDataRange().getValues(); // Remove header data.shift(); var date = new Date(); var currYear = date.getFullYear(); var output = {}; data.forEach(function(row){ var dob = new Date(row[3]); var dobYear = dob.getFullYear(); /* * Create full name property within output object. * Again the full name property is an object. * */ output[row[2]] = {}; /* * Assign DOB property to full name object...