I'm using the admin.analytics.getFile method to retrieve some data for an app I'm building. I can't figure out in apps script how to push the result of an api call, which I've formatted, to an array for further manipulation.
I'm at a stage where I have each user's data, on one row per user in a sheet as a result of some scripting. My thoughts were to try to loop through the sheet, wrap each cell in curly bracers to make objects (each user's data is stored in one cell), and then push each object to an array.
function convertSplitDataToObjectArray (departmentNumbers,splitData) {
//convert split data to object array, return splitDataAsObjectArray;
var placeholderArray = [];
for (let i=1; i<=363; i++) {
placeholderArray.push(raw.getRange(i,1).getValue());
}
var splitDataAsObjectArray = placeholderArray.map((x) => {
return {x};
});
};
This is what I've come up with. I could be being incredibly nooby, but I had expected {x} to simply wrap each string in curly bracers. Instead it returns {x="team_id":"17291125", etc etc... }
My goal would be for the contents of each cell to become objects - they are currently strings, in a key:value format. I feel like I'm not miles away from something, but any help would be appreciated.
EDIT:
Sample source data: "team_id":"redacted","date":"2024-01-31","user_id":"redacted","email_address":"redacted","is_guest":false,"is_billable_seat":true,"is_active":true,"is_active_ios":false,"is_active_android":true,"is_active_desktop":false,"reactions_added_count":1,"messages_posted_count":7,"channel_messages_posted_count":1,"files_added_count":0,"is_active_apps":false,"is_active_workflows":false,"is_active_slack_connect":false,"total_calls_count":0,"slack_calls_count":0,"slack_huddles_count":0,"search_count":18,"date_claimed":1595412410 // This is what raw.getRange(i,1).getValue() returns. Each of these is a string.
Sample existing result: {x="team_id":"redacted",.....}
Sample desired result - an array of objects of the form: { "team_id":"redacted","date":"2024-01-31","user_id":"U01AQD7JT71","email_address":"[email protected]",...}
If
xis"team_id":"17291125", then you can use JSON.parse() to convert it to a object.