Last active
May 27, 2018 15:41
-
-
Save cms-jakes/4d6b96b0c2dea62e4a28db7d5f4765c8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| //////////////////////////////////////////////////////////////////////// | |
| //The function takes two inputs: | |
| //url = Spreadhsheet URL | |
| //sheetName = name of sheet in Spreadsheet you want to convert to json | |
| //The resulting json objects will be a named based on text in the cells of row 1 with spaces removed | |
| //////////////////////////////////////////////////////////////////////// | |
| function getSpreadsheetData(ssURL,sheetName){ | |
| var ss = SpreadsheetApp.openByUrl(ssURL); | |
| var sheet = ss.getSheetByName(sheetName); | |
| var data = sheet.getDataRange().getValues(); | |
| var sheetArray = []; | |
| var headers = data[0] | |
| var jsonArray = []; | |
| for(var i=1; i<data.length; i++) { | |
| var line = data[i]; | |
| var json = new Object(); | |
| for(var j=0; j<headers.length; j++) { | |
| var header = headers[j].replace(/\s/g, ''); | |
| json[header] = line[j]; | |
| } | |
| jsonArray.push(json); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment