cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Frequent Visitor

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
Highlighted
Super User II
Super User II

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.
Highlighted

 

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

 

 

Highlighted

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.

Highlighted

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",
}
]

 

 
Highlighted

Hello mysticode,

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

Highlighted

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

Highlighted

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

Highlighted

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

Highlighted

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
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

News & Announcements

Community Blog

Stay up tp date on the latest blogs and activities in the community News & Announcements.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Community Highlights

Community Highlights

Check out the Power Platform Community Highlights

Top Solution Authors
Top Kudoed Authors
Users online (8,662)