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.

View solution in original post

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
MPA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

V3_PVA CAmpaign Carousel.png

Community Challenge - Giveaways!

Participate in the Power Virtual Agents Community Challenge

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

PowerPlatform 768x460.png

Microsoft Learn

Check out our new Discover Your Career Path blog post series and get all the details.

Top Solution Authors
Users online (1,142)