cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
arslanarif
Helper I
Helper I

How to compare two JSON arrays and create an array for the Matching values

Good day. Thank you for your interest.

 

I have to two arrays that I want to compare and match one against the other. The first (1st) Array will only have two(2) properties and values. The (2nd) Array will have many more and this is the array the 1st one is being compared to find the MATCHING two values (Parameter1_higher & Parameter2_lower). Based on the match, I then want to get the (3)rd value from the (2nd) Array

 

In the first array there are two variables from previous steps. Those integer variables just dynamically set the variable to what was in the 'Get_record'. For example (i.e. 506850000). In the (2nd) Array, the expressions are also dynamically set from an Object Variable. They are supposed to be the matching choice values to the variables set in the (1st) Array. For example (i.e. 506850000).  

 

Any help would be much appreciated. Please let me know if you have any more information for clarity.

 

Sample of the json is shared below. It's supposed to match against the 1st two objects in the (2nd) Array and extract the value of "100"

 

Best Regards,

Sunny

 

ARRAY 1

[
{
"Parameter1_higher": "506850007",
"Parameter2_lower": "506850006"
}
]

ARRAY 2:

[
{
"Parameter1_higher": "506850007",
"Parameter2_lower": "506850006",
"Amount": "100"
},
{
"Parameter1_higher": "506850002",
"Parameter2_lower": "506850003",
"Amount": "200"
},
{
"Parameter1_higher": "506850004",
"Parameter2_lower": "506850005",
"Amount": "300"
},
{
"Parameter1_higher": "506850006",
"Parameter2_lower": "506850007",
"Amount": "400"
},
{
"Parameter1_higher": "506850008",
"Parameter2_lower": "506850009",
"Amount": "500"
}
]

 

Array 1:

Arrary 1Arrary 1Array 2Array 2

1 ACCEPTED SOLUTION

Accepted Solutions
takolota
Super User
Super User

@arslanarif 

 

I’m not sure why you are using all those variables. You may want to share more of your flow so people may help you simplify it.

 

But for your main request, you should be able to write an advanced conditional in a Filter array action to get just the objects/items with those set values for those fields. Something like…

 

 

@and(equals(item()?['Parameter1_higher'], first(variables('VarCombo'))['Parameter1_higher']), equals(item()?['Parameter2_lower'], first(variables('VarCombo'))['Parameter2_lower']))

 

 

View solution in original post

3 REPLIES 3
takolota
Super User
Super User

@arslanarif 

 

I’m not sure why you are using all those variables. You may want to share more of your flow so people may help you simplify it.

 

But for your main request, you should be able to write an advanced conditional in a Filter array action to get just the objects/items with those set values for those fields. Something like…

 

 

@and(equals(item()?['Parameter1_higher'], first(variables('VarCombo'))['Parameter1_higher']), equals(item()?['Parameter2_lower'], first(variables('VarCombo'))['Parameter2_lower']))

 

 

arslanarif
Helper I
Helper I

@takolota 

 

Thank You! Worked with minor fixes. The working expression is below:

 

1. Variables is supposed to be plural: first(variables('VarCombo'))['Parameter1_higher'] --- 

2. typo: supposed to be: item()['Parameter1_higher'] ---missing the 'e' in Parameter

 

@and(equals(item()?['Parameter1_higher'], first(variables('VarCombo'))['Parameter1_higher']), equals(item()?['Parameter2_lower'], first(variables('VarCombo'))['Parameter2_lower']))

 

Thank You again and Best Regards,

Sunny

takolota
Super User
Super User

@arslanarif 

 

Thanks.

And sorry for the typos, I usually write these from my phone off the top of my head.

 

I edited the expression to fix some of those in the solution answer.

Helpful resources

Announcements
Power Automate News & Announcements

Power Automate News & Announcements

Keep up to date with current events and community announcements in the Power Automate community.

Power Automate Community Blog

Power Automate Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Users online (5,409)