How to know if a variable is Object or Array

Minh Pham 21 Reputation points
2021-08-26T11:44:35.53+00:00

Hi, currently I am using Xpath to work on an XML file, and I notice that the return of Xpath can be an object or an array. This will be depended on the input XML file, and I can not control the content of the XML file. So I need to have a condition so that if the Xpath output is an object, I will handle in a way; and if the Xpath output is an array, I will handle in another way. How can I achieve that?

126725-image.png

Azure Logic Apps
Azure Logic Apps
An Azure service that automates the access and use of data across clouds without writing code.
3,542 questions
0 comments No comments
{count} votes

Accepted answer
  1. Pramod Valavala 20,656 Reputation points Microsoft Employee Moderator
    2021-08-26T16:59:03.447+00:00

    @Minh Pham I believe there isn't any way to get the type of a value in Logic Apps and on top of that - strings, arrays, and objects are all treated as collections.

    One way I could think of is to use a method that works only on arrays like length to validate the type. If this expression succeeds, then it's an array otherwise an object (I assume here you don't have a string output from your xpath). You can configure run after in a parallel branch to continue processing as if the value is an object.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.