cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
marktait
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
mysticode
Frequent Visitor

This did not work.

 

I think it is because "link" is a property of an object in my array, instead of being the primary object itself?

 

JSON Body:

[
  {
    "parent": {
      "display_value": "12345",
      "link": "https://demosite.com"
    },
    "size": "small",
    "shadow": "false",
  }
]

Schema used:

{
  "type": "array",
  "items": {
    "type": "object",
    "properties": {
      "parent": {
        "type": "object",
        "properties": {
          "display_value": {
            "type": "string"
          },
          "link": {
            "type": "string"
          }
        }
      },
       "size": {
        "type": "string"
      }   
      "shadow": {
        "type": "string"
      }   
    }
  }
}

Hopefully this clears this up!

This is the command I used to create the JSON in PowerApps for testing:

ClearCollect(
    colTest,
    {
        parent: {
            display_value: "123",
            link: "https://demo.com"
        },
        shadow: "false"
    },
    {
        parent: {
            display_value: "12345",
            link: "https://demo2.com"
        },
        shadow: "false"
    }
)

I'll try putting your sample and schema into Flow to test.

I think there is a typo in the schema provided in your post - there should be a comma before the "shadow" as below:

{
  "type": "array",
  "items": {
    "type": "object",
    "properties": {
      "parent": {
        "type": "object",
        "properties": {
          "display_value": {
            "type": "string"
          },
          "link": {
            "type": "string"
          }
        }
      },
       "size": {
        "type": "string"
      },   
      "shadow": {
        "type": "string"
      }   
    }
  }
}

I created a Flow triggered by PowerApps with a Response step using the provided JSON and schema (with the correction noted above). I assigned the returned value to the collection colTest - the formulas previously posted worked for me.

mysticode
Frequent Visitor

I have checked my schema, and the comma is there. I typo'd in my post reply above.

 

In my current Gallery, my four labels have Text properties of: ThisItem.<column names here>


The gallery's Item property is set up to be: enhancements

 

I have a button, that is the following OnSelect property: ClearCollect(enhancements,EnhancementItems.Run())

Note: This was done to pull all the data from the Flow's JSON output.

 

All of my labels are successfully pulling in data so far for the Gallery.

 

Are you recommending I modify my ClearConnect property to specifically select the fields to put in from my Flow, instead of just pulling in all of them?

I note in one of your earlier posts you are referring to .Parent.link

In the JSON it is .parent.link (lower case P).

Parent is an object you can reference (e.g. you can set the width of a label to Parent.Width).

Maybe this is causing the issue.

Can you try checking your capitalisation? 

mysticode
Frequent Visitor

In the labels, I tried:

First(enhancements).parent.link

and

ThisItem.parent.link

 

Both times the error is: Invalid use of '.'

 

As a test to make sure that the First property saw my data, I tried First(enhancement).sys_created_on (this is another column of data from my JSON output), and it created repeating data across my gallery entries:

image.png

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

secondImage

Power Apps Community Call

Please join us on Wednesday, October 20th, at 8a PDT. Come and learn from our amazing speakers!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

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.

Top Solution Authors
Users online (1,741)