Output of my array filter:
As reference, the array filter is using a contains function looking for two criteria to match in a large excel file based off the value provided in two variables. I was testing to see what happens if intentionally setting variable values to something I know is not in the excel table for error handling. My filter array works perfect for items that are in the excel table but when an item is not in the excel table the output of the filter array is below.
{
"name": []
}
This to me means that the criteria I was searching for does not exist in the excel table and because of that I want to trigger other actions to take place. I was trying to use a Compose action and the empty function to then perform certain action if the result was true meaning the array was empty. However, the empty function returns the results of false and not true so I’m having a little trouble.
Can someone please help advise me on what I am not understanding correctly here or make suggestions to achieve the desired results?
You aren't quite understanding the JSON here. The output of the array is a named property called body which has a value of an array. So when you do length() of the body of the filter array you are doing a length of the body array. If you store the output of the filter array in a variable or a compose then it will become a JSON string and length on that object won't work.
In your Parse JSON 1 screenshot you have an object called Name that has a property of type array called body. Length in that case should be of the body. If you look at the filter array you will see that Name isn't there. Its just Body, which is of type array.
@Pstork1, thanks again for all the help here. 🙂 I'm still pretty new to using power automate so I'm still learning the basics.
Going back to my simple example I realized I was trying to use the length function on the incorrect part of the outputs.
I guess I'm still just struggling with some of the concepts, but I'll work my way through it. Thanks again.
The output of a filter array is an array, not an object. You can see that I am doing just that from my screenshot. Based on the screenshots you are showing I don't see an object either. As you can see from the screenshot below also. The input to a filter array needs to be an array and the output is a filtered version of that array.
The square brackets are the JSON syntax for an array, not an object. Objects are curly braces. An empty array would be []. That suggests there is something wrong with your filter.
@Pstork1, thank you for the additional detail. I cannot perform the length function directly on the output of the filter array because it's an object so I get an error. This is why I had tried using a compose and converting the object to an array so I could use the length function.
The first image below shows where I have intentionally chosen a value I know won't be found in the excel file the filter array is filtering and shows the output of the filter array.
The second image shows the error message I get when trying to test the length function directly on the output of the filter array. "InvalidTemplate. Unable to process template language expressions in action 'Compose' inputs at line '0' and column '0': 'The template language function 'length' expects its parameter to be an array or a string. The provided value is of type 'Object'.
I've tried to replicate your issue, but am unable to. Here's the flow code that works for me. When I filter out all the records it goes to false. If I don't filter out all the records it goes to true.
Are you using length on the output of the filter array directly or are you storing it in something first, like a compose? I'll try to replicate your issue, but the JSON you are showing for the body is showing an empty array, but which should show a length of 0 not 1.
@Pstork1 , thank you for the response.
I tested for length and the output is 1. The problem is that even though the output is 1 I'm having trouble with what to do now. The outputs body of the filter array is [].
Let me start over.....The output of the filter array for items not containing the criteria is [], see image. In my example I am looking through a database of zip codes based on a variable defined in the flow and I'm extracting information from another column of data that is associated with the zip code being found in the database.
If i use the compose action on the outputs of this filter I get this.
If I run the Pare JSON action, I also get the same result. The reason I was using Parse Jason is because if the filter array did find a match then there would be an object with several pieces of information, and I used the Parse Jason to extract only individual values I needed from the output.
When the value is not found in the database I am searching I get the output of []. Since I believe this is an object I can't directly test the length before converting this to an array. So I used a compose action and create an array from an object function and this was the output.
Then I can run the a compose action with the length function to get the length
However, at this point I am stuck because I'm trying to find a way so that when a result isn't returned and I get not information in the body [], I can trigger a message to myself for the value not being found in the database and then go on to other actions.
I hope this makes sense.
To test for an empty array use the length() function instead of empty. If the length is zero then the array has no elements. If the length is greater than zero it does.
WarrenBelz
68
Most Valuable Professional
mmbr1606
41
Super User 2025 Season 1
MS.Ragavendar
38