cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
virakones
Responsive Resident
Responsive Resident

How to Select value from Object using value from array as the Key?

Hello,

 

I have an Adaptive Card that returns to me a submitted response that includes all dynamic responses in a single object.

 

Those dynamic inputs have an id assigned - this id is the key containing the value I want assigned to it.

 

 

{
    "body": {
        "5caf4a2f-b16b-eb11-a812-000d3a987ca7": "Value1",
        "fc02e508-b26b-eb11-a812-000d3a987ca7": "Value2"
    }
}

 

 


I have a separate array to compare the object against:

 

 

{
  "ids": [
    {
      "id": "5caf4a2f-b16b-eb11-a812-000d3a987ca7"
    },
    {
      "id": "fc02e508-b26b-eb11-a812-000d3a987ca7"
    }
  ]
}

 

 


In the end, I want to be able to transform the data to below:

 

 

{
  "data": [
    {
      "id": "5caf4a2f-b16b-eb11-a812-000d3a987ca7",
      "value": "Value1"
    },
    {
      "id": "fc02e508-b26b-eb11-a812-000d3a987ca7",
      "value": "Value2"
    }
  ]
}

 

 


Question: How would I be able to iterate through the values from the array of id's and select the values from an object using those ids as the key?

1 ACCEPTED SOLUTION

Accepted Solutions
v-yiwenxie-msft
Microsoft
Microsoft

Hi @virakones 

 

The following flow is for your reference:

2.15-4.PNG

 

The inputs for all the ‘compose’ actions are:

 

Compose:

{

  "ids": [

    {

      "id": "5caf4a2f-b16b-eb11-a812-000d3a987ca7"

    },

    {

      "id": "fc02e508-b26b-eb11-a812-000d3a987ca7"

    }

  ]

}

 

Compose 3:

outputs('Compose')?['ids']

 

Compose 2:

{

  "body": {

    "5caf4a2f-b16b-eb11-a812-000d3a987ca7": "Value1",

    "fc02e508-b26b-eb11-a812-000d3a987ca7": "Value2"

  }

}

 

Compose 5:

outputs('Compose_2')?['body']

 

Compose 4:

outputs('Compose_5')[items('Apply_to_each')?['id']]

 

Compose 6:

{

"id": "@{items('Apply_to_each')?['id']}",

"value": @{outputs('Compose_4')}

}

 

Best Regards,
Community Support Team _ Kira Xie
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
v-yiwenxie-msft
Microsoft
Microsoft

Hi @virakones 

 

The following flow is for your reference:

2.15-4.PNG

 

The inputs for all the ‘compose’ actions are:

 

Compose:

{

  "ids": [

    {

      "id": "5caf4a2f-b16b-eb11-a812-000d3a987ca7"

    },

    {

      "id": "fc02e508-b26b-eb11-a812-000d3a987ca7"

    }

  ]

}

 

Compose 3:

outputs('Compose')?['ids']

 

Compose 2:

{

  "body": {

    "5caf4a2f-b16b-eb11-a812-000d3a987ca7": "Value1",

    "fc02e508-b26b-eb11-a812-000d3a987ca7": "Value2"

  }

}

 

Compose 5:

outputs('Compose_2')?['body']

 

Compose 4:

outputs('Compose_5')[items('Apply_to_each')?['id']]

 

Compose 6:

{

"id": "@{items('Apply_to_each')?['id']}",

"value": @{outputs('Compose_4')}

}

 

Best Regards,
Community Support Team _ Kira Xie
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

@v-yiwenxie-msft 

Thank you! This has been bugging me for a while. I appreciate the help - there is no way I would have considered using those compose actions the way you outlined but the end result is fantastic. 

NielsL
Helper V
Helper V

@virakones thank you for pointing me in the direction of this thread. This is exactly what I am looking for. 

 

Can you share with me, how you created the separate array with the IDs to compare against?

NielsL
Helper V
Helper V

Nevermind, I got it working. I always thought it would be possible somehow, but I would never have come up with that solution myself. 

 

Thanks both of you, @virakones @v-yiwenxie-msft 

Helpful resources

Announcements
October Events

Mark Your Calendars

So many events happening this month - don't miss out!

 WHAT’S NEXT AT MICROSOFT IGNITE 2022

WHAT’S NEXT AT MICROSOFT IGNITE 2022

Explore the latest innovations, learn from product experts and partners, level up your skillset, and create connections from around the world.

Register for a Free Workshop.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

Users online (2,719)