Efficiently Filter a JSON object in Power Automate

man love people woman

Here is an interesting sample JSON object {}, that contains a JSON array [] with 3 objects. The final solution will have 3000 objects. The aim is to retrieve two key values from the object whilst checking another nested array for a common string ‘ACABA’. Whilst it is perfectly acceptable to use an apply to each and loop through all 3000 objects, this will eat into your 24 hour API limit on the Power Platform and whilst this hasn’t really been a concern in the past, Microsoft are lowering those limits and will begin enforcement once a new admin level report has been released.

On a sliding 24 hour period, a user will have 6,000 api requests as an O365 licensed user, this will increase to 40,000 for those that are licensed per user and 250,000 as a per flow. There is no time like the present to understand efficiency in your flows.

The problem

The solution

In two simple actions (and therefore two api calls), it is possible to re-purpose the array and filter the result. With a Select Action we can include the 3 key values, the id, product id and the tags array. We can then filter on this new array by converting the tags array into a string. We cannot easily repurpose the tags array in the select without using something like Xpath, so I will leave that for another day. It is worth noting that string comparison is case sensitive, therefore you might want to consider using toupper() or tolower().

With the original object in the compose, the Select is repurposing the data from the object to form a new array. We must supply an array [] to the select, in this case the data array []. This can be accessed from the result object {}. An expression for this might look like follows outputs(‘compose’)?[‘result/data’].

Output of the select contains a repurposed array.

With this newly formed array, we can then filter on the tags array as a string for the key string ‘ACABA’ using the condition “contains”. This will reduce the original array of three objects to two, as we know the third does not contain the required string. This flow will run in a matter of seconds and consume only two API calls (three if you count the compose containing the original Object).

The expressions used in this solution are:

item()?['id']
item()?['productid']
item()?['tags']
string(item()?['tags'])
Repurpose and filter an array using Power Automate

How did you find that? Please let me know below and make sure you check out my other content on YouTube. Find me on social media platforms as DamoBird365 and make sure you say hi. Thanks for reading.

Share