Search code examples
javascriptgoogle-apps-scriptgoogle-app-maker

Converting the response of the Google Admin SDK with curly-brace strings with items into a multidimensional array


I have data that I'm getting from the G Suite Admin SDK that looks like this:

[{orgUnitPath=/Test, kind=admin#directory#orgUnit, blockInheritance=false, name=No Public Sharing, description=, etag="string", orgUnitId=id:00000, parentOrgUnitPath=/, parentOrgUnitId=id:111111}, ...]

How can I convert this into an array like this:

[[[orgunitpath, test],[orgunitid,000000]],[[orgunitpath, test],[orgunitid,000000]],[[orgunitpath, test2],[orgunitid,222222]],[[orgunitpath, test],[orgunitid,222222]]]

I'm ultiamtely looking to import this data into a SQL datasource in AppMaker.


Solution

  • You can easily do this with Array#map

    Snippet:

    var res; //[{orgUnitPath:/Test, orgUnitId:id:00000, parentOrgUnitPath=/, parentOrgUnitId=id:111111}, ...]
    var array=res.map(function(obj){
        return [['orgunitpath', obj['orgUnitPath']],['orgunitid',obj['orgUnitId']]]
    })