Skip to content

Instantly share code, notes, and snippets.

@simenbrekken
Created October 24, 2012 21:17
Show Gist options
  • Save simenbrekken/3948950 to your computer and use it in GitHub Desktop.
Save simenbrekken/3948950 to your computer and use it in GitHub Desktop.
Export Google Spreadsheet as JSON
function exportJSON() {
var sheets = SpreadsheetApp.getActiveSpreadsheet().getSheets();
var result = sheets.reduce(function(result, sheet) {
var id = sheet.getName().toLowerCase();
var data = sheet.getDataRange();
var values = data.getValues();
result[id] = values.map(function(row) {
return row.map(function(column) {
return Math.round(column) || column;
}).filter(Boolean);
}).filter(function(row) {
return !!row[0];
});
return result;
}, {});
var app = UiApp.createApplication().setTitle('Exported JSON');
var textArea = app.createTextArea().setWidth('100%').setHeight('400px').setText(JSON.stringify(result));
app.add(textArea);
SpreadsheetApp.getActiveSpreadsheet().show(app);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment