cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
marktait
Level: Powered On

Powerapps problem accessing JSON collection

Hi.

 

I'm having difficulty accessing data in a collection, via PowerApps.

 

I create the collection with this:

 

Collect(coll15,mt.GetAnswers("3b....da","application/json",{question:"eco"}))

 

Using Developer Tools -> Network tab -> Response body - the following JSON data is returned:

 

{
  "answers": [
    {
      "answer": "This is the answer",
      "questions": [
        "Private vehicle eco renewal"
      ],
      "score": 82.901087775826454
    }
  ]
}

 

The collection is created.

 

I then add a gallery control to my page - however the only options I have to bind to the labels are: ThisItem.Value

 

If I try to enter ThisItem.Value.answer I get the error: Invalid use of '.'

 

If I enter ThisItem.answers.answer I get the error: Invalid name

 

Is there any way for me to access the answer text within the collection?

 

Thanks for any help,

 

Mark

15 REPLIES 15
Super User
Super User

Re: Powerapps problem accessing JSON collection

I wasn't aware you could create a Collection out of a JSON object that way. Did you look at the collection after it was created by the collect() to see how it is structured? In PowerApps Web Studio > File > Collections > Select a collection. This should show you what the collection looks (columns and rows).



--------------------------------------------------------------------------------
If this post helps answer your question, please click on “Accept as Solution” to help other members find it more quickly. If you thought this post was helpful, please give it a Thumbs Up.
marktait
Level: Powered On

Re: Powerapps problem accessing JSON collection

 

Hi Jeff.

 

I can create a collection like this:

 

Collect(faqs, {
question:{answers: [{answer: "This is answer1",
      questions: ["This is question 1"],
      score: 93.2
    }
  ]
}})

 

 

That then creates this:

 

 

 

ss1.PNGss2.PNGss3.PNGss4.PNG

 

But within Poweapps - I can't seem to reference beyond faqs.question:

 

ss5.PNG

 

So the collection is there - I just can't seem to get to the parts I need.

 

Thanks, Mark

 

 

Mike8
Level 10

Re: Powerapps problem accessing JSON collection

Hello @marktait,

If you are still looking an answer to this,
Label1.Text = LookUp(LookUp(faqs,true,question).answers,true,Value).answer

Check your syntax in the expression you create the collection and notice when the expression LookUp(LookUp(faqs,true,question).answers,true,Value).answer, has a dot, and when a LookUp, in order to go deeper.
If you have questions I can help more.

mysticode
Level: Powered On

Re: Powerapps problem accessing JSON collection

I have a collection created, pulling data from an array. In my array, I have multiple properties in my objects, but I can't seem to get at those properties. In the below example, I'd want to get the "link" property of the "parent" object.

 

My array is coming in as: 

 

[
{
"parent": {
  "display_value": "123",
  "link": "https://demo.com"
   },
"shadow": "false",
"updated_on": "2018-12-07 10:30:52 AM",
"number": "12345",
"u_task_for": "",
"top_program": "",
"schedule_start_date": "2017-10-11 12:35:47 PM",
"state": "Draft",
"sys_created_by": "M2R",
"knowledge": "false",
"order": "",
"work_duration": "",
"short_description": "abcd",
}
]

 

 
Mike8
Level 10

Re: Powerapps problem accessing JSON collection

Hello mysticode,

Does the following work for you?
LookUp(CollectionName,true, parent.link)

mysticode
Level: Powered On

Re: Powerapps problem accessing JSON collection

Thank you for your reply.

 

I tried this, and an error is returning. Please note that I am doing this in a gallery (not sure if that changes anything):

 

powerapps-json-error-lookup.png

Super User
Super User

Re: Powerapps problem accessing JSON collection

I loaded the JSON you supplied into a collection, colTest.

To get the value of the first item, use the following (e.g. in the text property of a label):

First(colTest).parent.link

To show in a gallery, I simply set the Gallery Items property to colTest

I then created to labels with the following text properties:

ThisItem.parent.display_value

ThisItem.parent.link

Mike8
Level 10

Re: Powerapps problem accessing JSON collection

Okay, I see.
If you want to display it in a gallery, you can try:
Gallery1.Items : enhancements
Label1.Text : Parent.link

mysticode
Level: Powered On

Re: Powerapps problem accessing JSON collection

When I try to use in a Text property function:

First(colTest).parent.link

The error coming back is:

 

Invalid use of '.'

 

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors (Last 30 Days)
Users online (6,149)