Skip to content

Instantly share code, notes, and snippets.

@jonobr1
Last active November 23, 2020 19:52
Show Gist options
  • Save jonobr1/602e9e3283d628ff4bec4508043daa30 to your computer and use it in GitHub Desktop.
Save jonobr1/602e9e3283d628ff4bec4508043daa30 to your computer and use it in GitHub Desktop.
Google AppScript for serving your Sheet as a publicly accessible JSON file. Following these steps in your Google Sheets: https://levelup.gitconnected.com/turn-your-google-sheet-into-a-web-application-f766f1ff8b98
function doGet(e) {
var sheet = SpreadsheetApp.getActiveSheet();
var range = sheet.getDataRange();
var values = range.getValues();
var result = [];
for (var i = 0; i < values.length; i++) {
var row = [];
for (var j = 0; j < values[i].length; j++) {
if (values[i][j]) {
row.push(values[i][j]);
} else {
row.push('');
}
}
result.push(row);
}
return ContentService.createTextOutput(JSON.stringify(result))
.setMimeType(ContentService.MimeType.JSON);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment