cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Helper II
Helper II

Looping through an Array

Hello,

 

I am trying to loop through an Array which has key, value pairs that is something like this:

 

[
  {
    "Q1": "65a4bea6-ef6e-ea11-a811-000d3aa3ee47"
  },
  {
    "Q5": "5b564b8a-a17c-ea11-a811-000d3aa3ee47"
  },
  {
    "Q11": "c97a7c94-a17c-ea11-a811-000d3aa3ee47"
  },
  {
    "Q12": "33fcc49e-a17c-ea11-a811-000d3aa3ee47"
  },
  {
    "Q13": ""
  },
  {
    "Q14": ""
  }
]

 

 

However how do i retrieve the value for a specific key say for Q1 or Q2 etc...?

I tried something like this with functions to reflect the function within a compose action:  variables('QuestionReferenceArray')[0]['Q1']

 

variables('QuestionReferenceArray')[int(variables('Question Reference Index'))][outputs('Compose_14')]

 

 

This is the error i get:

 

InvalidTemplate. Unable to process template language expressions in action 'Compose_12' inputs at line '1' and column '23867': 'The template language expression 'variables('QuestionReferenceArray')[int(variables('Question Reference Index'))][outputs('Compose_14')]' cannot be evaluated because property ''Q1'' doesn't exist, available properties are 'Q1'. Please see https://aka.ms/logicexpressions for usage details.'.

 

 

Not sure if i am doing this right but would be great if someone could guide me how i could read array data based on a key. 

My flow run where the error occurs:

Array Flow 1.PNG

 

Flow Actions:

Array Flow 2.PNG

Thanks in advance for the help.

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Support
Community Support

Re: Looping through an Array

Hi @Nithin_Vanam,

 

The Index in the array is not correct, the index of array starts from 0, the index of the first member should be 0, so you should sub 1 when you input expression, for example:

variables('QuestionReferenceArray')[add(int(variables('Question Reference Index')),-1)][outputs('Compose_14')]

 

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.

View solution in original post

2 REPLIES 2
Highlighted
Super User III
Super User III

Re: Looping through an Array

Hello @Nithin_Vanam 

 

Please elaborate in what you are trying to achieve. From what I can gather would this work:

 

I took your example from above and added it to a Compose action.

[
  {
    "Q1": "65a4bea6-ef6e-ea11-a811-000d3aa3ee47"
  },
  {
    "Q5": "5b564b8a-a17c-ea11-a811-000d3aa3ee47"
  },
  {
    "Q11": "c97a7c94-a17c-ea11-a811-000d3aa3ee47"
  },
  {
    "Q12": "33fcc49e-a17c-ea11-a811-000d3aa3ee47"
  },
  {
    "Q13": ""
  },
  {
    "Q14": ""
  }
]

 

Now I added a Parse JSON action, and added the Array as the content.

See below for the Schema I usedSee below for the Schema I used

 Next I added a Apply to each loop and set the input as the Body from the Parse JSON action

 This will iterate through each item.

 

If you want to just get one value, there is no need for the loop as all data can be referenced individually thanks to the Parse JSON action

 

The schema that was used in the Parse JSON action:

{
    "type": "array",
    "items": {
        "type": "object",
        "properties": {
            "Q1": {
                "type": "string"
            },
            "Q5": {
                "type": "string"
            },
            "Q11": {
                "type": "string"
            },
            "Q12": {
                "type": "string"
            },
            "Q13": {
                "type": "string"
            },
            "Q14": {
                "type": "string"
            }
        },
        "required": []
    }
}




Did I answer your question? Mark my post as a solution!

If you like my post please hit the Thumbs Up


Proud to be a Flownaut!


Check out my blog for Power Automate tips, tricks, and guides
FlowAltDelete




Highlighted
Community Support
Community Support

Re: Looping through an Array

Hi @Nithin_Vanam,

 

The Index in the array is not correct, the index of array starts from 0, the index of the first member should be 0, so you should sub 1 when you input expression, for example:

variables('QuestionReferenceArray')[add(int(variables('Question Reference Index')),-1)][outputs('Compose_14')]

 

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.

View solution in original post

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

Power Platform ISV Studio

Power Platform ISV Studio

ISV Studio is designed to become the go-to Power Platform destination for ISV’s to monitor & manage published applications.

Tech Marathon

Maratón de Soluciones de Negocio Microsoft

Una semana de contenido con +100 sesiones educativas, consultorios, +10 workshops Premium, Hackaton, EXPO, Networking Hall y mucho más!

Top Solution Authors
Top Kudoed Authors
Users online (6,387)