web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Power Automate - Building Flows
Answered

Nested Array Extraction Help

(0) ShareShare
ReportReport
Posted on by

I have the following output from a GraphAPI call, of which I cant work out a way to extract the groupTypes and ID. Could someone lend me some guidence please

{
 "statusCode": 200,
 "headers": {
 "Transfer-Encoding": "chunked",
 "Vary": "Accept-Encoding",
 "Strict-Transport-Security": "max-age=31536000",
 "request-id": "1f9171fa-6c37-4877-9a7e-a61da01a929e",
 "client-request-id": "1f9171fa-6c37-4877-8a7e-a61da02a929e",
 "x-ms-ags-diagnostic": "{\"ServerInfo\":{\"DataCenter\":\"Australia Southeast\",\"Slice\":\"E\",\"Ring\":\"4\",\"ScaleUnit\":\"002\",\"RoleInstance\":\"ML1PEPF00004B03\"}}",
 "x-ms-resource-unit": "1",
 "OData-Version": "4.0",
 "Cache-Control": "no-cache",
 "Date": "Sun, 29 May 2022 02:26:02 GMT",
 "Content-Type": "application/json; odata.metadata=minimal; odata.streaming=true; IEEE754Compatible=false; charset=utf-8",
 "Content-Length": "445"
 },
 "body": {
 "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#directoryObjects(groupTypes,id)",
 "value": [
 {
 "@odata.type": "#microsoft.graph.group",
 "groupTypes": [
 "DynamicMembership"
 ],
 "id": "badc0e9e-d736-4534-b2c2-7aed3280a035"
 },
 {
 "@odata.type": "#microsoft.graph.group",
 "groupTypes": [
 "Unified"
 ],
 "id": "14a7c19e-db29-4e5c-82ec-657686b5f27d"
 },
 {
 "@odata.type": "#microsoft.graph.group",
 "groupTypes": [
 "Unified"
 ],
 "id": "1b8d728a-bf51-4ddd-b167-9e945f734d77"
 }
 ]
 }
}

 

I have the same question (0)
  • eliotcole Profile Picture
    4,343 Moderator on at
    Re: Nested Array Extraction Help

    Hi, @LukePWilkins , have you taken a look at some of the recommendations on the side there?

     

    This has come up a few times in the past week and I reckon you'd probably find an easily bent solution there. 👍 🙂

  • eliotcole Profile Picture
    4,343 Moderator on at
    Re: Nested Array Extraction Help

    Simply Done

    Anyway, here you can simple do a select on the body/value array, and create a key of Group Ids, then in the value side put the expression:

    get GroupId.jpg

     

     

    item()?['groupTypes']

     

     

    This will provide each array as is.

     

    If you're confident that each one only has one group inside it (ie. it's checked prior to entry), then you can use:

     

     

    item()?['groupTypes'][0]

     

     

    That will pull the first value from the groupTypes array into that value field.

     

    If you only need it for a singular case, that's fine, if you want to manipulate the original input, then you can simply make a compose after you've generated your new value array, and call the original inside a setProperty() function, setting the value property to your newly generated value set. 🙂

     

    Going Overboard

    If you wanted to be even cleverer you could use an if() statement to set it to a singular value for just one, or the array for more, or even a join() of the array if you still want a singular value.

    As an Array:

    if(
     greater(
     length(
     item()?['groupTypes']
     ),
     1
     ),
     item()?['groupTypes'],
     item()?['groupTypes'][0]
    )
    

    As a String

    if(
     greater(
     length(
     item()?['groupTypes']
     ),
     1
     ),
     join(
     item()?['groupTypes'],
     ','
     ),
     item()?['groupTypes'][0]
    )

    Choice Between Two

    With a boolean variable choosing between array/string 😅:

    if(
     greater(
     length(
     item()?['groupTypes']
     ),
     1
     ),
     if(
     variables('stringPleaseVAR'), 
     join(
     item()?['groupTypes'],
     ','
     ),
     item()?['groupTypes']
     ),
     item()?['groupTypes'][0]
    )

     

  • Verified answer
    LW-28112008-0 Profile Picture
    on at
    Re: Nested Array Extraction Help

    @eliotcole thank you for taking the time to reply.

    It would be interesting to see the function syntax in your SELECT FROM field please

  • Verified answer
    eliotcole Profile Picture
    4,343 Moderator on at
    Re: Nested Array Extraction Help

    OK, it's not really relevant what I used (because I put your result in a Compose action! 😅), it's relevant what you use to get the code that you listed.

     

    So ... let us assume that the name of your Graph API call is just the standard one and you haven't renamed it. Then your From field would look like this:

    body('Send_an_HTTP_request')?['body/value']

    Or you could use this:

    body('Send_an_HTTP_request')?['body']?['value']

    Either should pull that array that you have there.

  • LW-28112008-0 Profile Picture
    on at
    Re: Nested Array Extraction Help

    Hello, that has given me some good guidence. 

    Where the return was producing [ "Dynamic ' ] for example, I was able to use the JOIN action to clean it up and return the Dynamic wording as a string.

     

    cheers for taking the time to reply

  • eliotcole Profile Picture
    4,343 Moderator on at
    Re: Nested Array Extraction Help

    Nice one, mate.

     

    If you select yours, or my, or both(!), answers as Solution it'll just close out the thread so folks can find it in the future as a solution to whatever they need it for.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Chiara Carbone – Community Spotlight

We are honored to recognize Chiara Carbone as our Community Spotlight for November…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 647 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 350 Moderator

#3
developerAJ Profile Picture

developerAJ 256

Last 30 days Overall leaderboard