Transforms the data of a given Spreadsheet Sheet to JSON.
- The frozen rows are taken as keys for the JSON.
- The data taken for the values is only that after the frozen rows
exportJSON(Spreadsheet)
- transforms the data in the given sheet to JSON.
@params ss
- SpreadsheetApp>Spreaddheet Class.
@returns Object[]
- Array of JSON objects.
getRowsData(Sheet)
iterates row by row in the sheer and returns an array of objects.
Each object contains all the data for a given row, indexed by its normalized column name.
@params sheet
- SpreadsheetApp>Sheet Class, the sheet object that contains the data to be processed.
@returns Object[]
- an Array of objects with the headers as keys.
getObjects(String[], String[])
, For every row in the data, generates an object.
Names of object fields are defined in keys.
@params data
- JavaScript 2d array.
@params keys
- Array of Strings that define the property names for the objects to create.
@returns Object[]
- JSON, an Array of objects.
getColumnsData(Sheet Object, RangeElement[], int)
iterates column by column in the input range and returns an array of objects.
Each object contains all the data for a given column, indexed by its normalized row name.
@params sheet
- the sheet object that contains the data to be processed
@params range
- the exact range of cells where the data is stored
@params (optional)rowHeadersColumnIndex
- specifies the column number where the row names are stored.
@returns Object[]
- an Array of objects.
normalizeHeaders(String[])
Returns an Array of normalized Strings.
@params headers
- Array of raw headers
@returns String[]
- Array of normalized headers.
normalizeHeaders(String[])
Normalizes a string by removing all alphanumeric characters
Uses camelCase to separate words. The output will always start with a lower case letter.
This function is designed to produce JavaScript object property names.
@params headers
- Array of raw headers
@returns String[]
- Array of normalized headers.
Example:
"First Name" -> "firstName"
"Market Cap (millions) -> "marketCapMillions
"1 number at the beginning is ignored" -> "numberAtTheBeginningIsIgnored"
Replace the Spreadsheed id with the ID of the Spreadsheet you want to transform
If you have useful new methods, or better ways of doing what this sample does, please feel free to...
- Fork it!
- Make marvels
- Submit a pull request :D
Based on the original gist from crstamps2