I have a flow set up that receives XML data from an API. If it returns only one item, it comes as an object, if more than one item, it's an array. My mind is going blank for the right expression. How would I add a condition that says 'if it's an object do something' otherwise 'if it's an array, loop through them'.
Hi @Anonymous,
There is no action or function that could determine an item is an array or object.
As a workaround, you could use the length() function to determine it, if the item is an object, it will fail, and you can make a branch to make the Flow could run when the length() function failed; if the item is an array, it will return a number, then Flow will go to the right side of array.
Best Regards,
Community Support Team _ Lin Tu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Thank you. I thought I had tried that but I realized I hadn't added it into its own variable if it failed.
Hi @Anonymous,
Yes, the short of workaround is every time the flow will report an error no matter it is an object or array.
I just thought of another way is convert the data into a string, then use contains() function to check it whether contains "[" and "]", because an array must contain "[" and "]", for example:
contains(string(outputs('Compose')),'[')
Best Regards,
Community Support Team _ Lin Tu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.
Learn to digitize and optimize business processes and connect all your applications to share data in real time.