cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
QuestionGuy
Regular Visitor

looking up array item without using index

I would like to be able to lookup the "Id" value then return the "value" value if the ID matches, is this possible using an expression? I cannot use the standard indexed values to reference the item since the array will eventually be modified(the goal is to prevent future failures due to the index changing when fields are added or removed from the array).

 

[
{
"id": 1035764787,
"value": "test1"
},
{
"id": 3859843254,
"value": "test2"
},
{
"id": 7654125785,
"value": "test3"
}

]

1 ACCEPTED SOLUTION

Accepted Solutions
ekarim2020
Super User
Super User

So, given the id 7654125785 you want to return "test3" for example. As @Pstork1 has stated, there isn't an expression or expressions that will do this.

 

Another option could be to transform the JSON array in to a JSON object - though using the Filter array action requires fewer steps.

2021-12-10_18-07-23.png

 Example:

2021-12-10_18-25-46.png

Select is used to select the data fields - if the dataset contain other fields.

 

2021-12-10_18-27-08.png

 

replace(replace(replace(string(body('Select')),'},{', ','),'[{','{'),'}]','}')

 

2021-12-10_18-27-18.png

 

2021-12-10_18-32-57.png

 

The expression in the Compose will either return the value or if no id is found, it will return empty.

2021-12-10_18-41-32.png

Ellis

View solution in original post

2 REPLIES 2
Pstork1
Dual Super User
Dual Super User

I can't think of any way to do this with just expressions.  But you could use a filter array action to filter the array down based on the ID value.  Then use First() to get that one remaining record out of the filtered array.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.
ekarim2020
Super User
Super User

So, given the id 7654125785 you want to return "test3" for example. As @Pstork1 has stated, there isn't an expression or expressions that will do this.

 

Another option could be to transform the JSON array in to a JSON object - though using the Filter array action requires fewer steps.

2021-12-10_18-07-23.png

 Example:

2021-12-10_18-25-46.png

Select is used to select the data fields - if the dataset contain other fields.

 

2021-12-10_18-27-08.png

 

replace(replace(replace(string(body('Select')),'},{', ','),'[{','{'),'}]','}')

 

2021-12-10_18-27-18.png

 

2021-12-10_18-32-57.png

 

The expression in the Compose will either return the value or if no id is found, it will return empty.

2021-12-10_18-41-32.png

Ellis

Helpful resources

Announcements
MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

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

Power automate tips 768x460 v2.png

Restore a Deleted Flow

Did you know that you could restore a deleted flow? Check out this helpful article.

Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

May UG Leader Call Carousel 768x460.png

What difference can a User Group make for you?

At the monthly call, connect with other leaders and find out how community makes your experience even better.

Users online (2,434)