cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
BenDonahue
Skilled Sharer
Skilled Sharer

Access data in an object in an array

After much parsing and filtering, I am left with the single record I need. This record is an object and it is in an array as the only element:

[
  {
    "@odata.etag""",
    "ItemInternalId""7d6ca98f-2bd8-45bb-aff8-e555db2ce2ee",
    "Q-ID""19",
    "QGroup""Std1",
    "Q""Is question1 correct?",
    "QOrder""1"
  }
]
How do I access Q in this object?
In my (clearly) wrong way of thinking, I came up with these wrong answers (the value of outputs('FA-forCurrentQuestionInOrder') is the above array):
outputs('FA-forCurrentQuestionInOrder')?['Q']
outputs('FA-forCurrentQuestionInOrder')?[0]['Q']
outputs('FA-forCurrentQuestionInOrder')?[0]?['Q']
outputs('FA-forCurrentQuestionInOrder')?['body/Q']
outputs('FA-forCurrentQuestionInOrder')?['body/Q/Value']
 
Thank you for your help.
 
1 ACCEPTED SOLUTION

Accepted Solutions
BenDonahue
Skilled Sharer
Skilled Sharer

And the correct answer is:
outputs('FA-forCurrentQuestionInOrder')?['body'][0]['Q']
 
When I was trying to access the data, I was attempting to use the index of the array element, but kept getting an error stating that I must use a name first and not a number. It turns out that the name it needed was 'body' then the rest works like normal (so far).
 
Later this same day, I attempted to use this pattern to access an element in an array that consisted of a series of data that were appended to an array variable, so, something like:
[1,f,7,8,e,sd,g,6,23,ds,7]
For this, I used a more standard syntax:
outputs('C-strArrResValues')?[0]
 
The first syntax was based off of the outputs from a Filter Array block.
The second syntax was based off of the outputs from a Compose block which was, in turn, simply the value of an array variable.

View solution in original post

3 REPLIES 3
BenDonahue
Skilled Sharer
Skilled Sharer

And the correct answer is:
outputs('FA-forCurrentQuestionInOrder')?['body'][0]['Q']
 
When I was trying to access the data, I was attempting to use the index of the array element, but kept getting an error stating that I must use a name first and not a number. It turns out that the name it needed was 'body' then the rest works like normal (so far).
 
Later this same day, I attempted to use this pattern to access an element in an array that consisted of a series of data that were appended to an array variable, so, something like:
[1,f,7,8,e,sd,g,6,23,ds,7]
For this, I used a more standard syntax:
outputs('C-strArrResValues')?[0]
 
The first syntax was based off of the outputs from a Filter Array block.
The second syntax was based off of the outputs from a Compose block which was, in turn, simply the value of an array variable.

Hi BenDonahue,

 

Thanks for sharing the solution.

 

Regards,

JAvier

@FCGALLEG,

I posted my experiences and I am trying to make sense of them. Can you confirm for me, please, the following:

 - When accessing a array created by a "Filter array" block, one needs to use ['body'] first

 - When accessing an array in an array variable, skip ['body'] and just use the indices.

 

OR

 

 - When accessing an array of objects, one needs to use ['body'] first

 - When accessing an array of simple data, skip ['body'] and just use the indices.

 

OR

 

 - Is the pattern something else entirely and, if so, what is that pattern?

 

Helpful resources

Announcements
Power Automate News & Announcements

Power Automate News & Announcements

Keep up to date with current events and community announcements in the Power Automate community.

Power Automate Community Blog

Power Automate Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Users online (3,206)