Created
May 15, 2023 12:06
-
-
Save Zakarialabib/4db3cf219e25506fe5a309177d746c0e to your computer and use it in GitHub Desktop.
Export json google sheet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function doGet() { | |
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Data"); | |
var range = sheet.getDataRange(); | |
var values = range.getValues(); | |
var headers = values[0]; | |
var data = values.slice(1); | |
var json = {}; | |
for (var col = 0; col < headers.length; col++) { | |
var header = headers[col]; | |
json[header] = []; | |
for (var row = 0; row < data.length; row++) { | |
if (data[row][col] != "") { | |
json[header].push(data[row][col]); | |
} | |
} | |
} | |
var output = ContentService.createTextOutput(JSON.stringify(json)); | |
output.setMimeType(ContentService.MimeType.JSON); | |
return output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment