cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
QuestionGuy
Frequent 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.

Join me at 365 and PWR EduCon in Chicago
EduCon Chicago 2022

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
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.

September Events 2022

Check out all of these events

Attend in person or online, there are incredible conferences and events happening all throughout the month of September.

Users online (4,686)