cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Helper V
Helper V

Accessing JSON elements more than one element deep / arrays (from a Custom Connector)

I have JSON coming back in the following format below. I can acccess 'root' level elements but not the part I"m interested in, which is queryResults.Result. I want to be able to access those elements, and count the rows etc. Any tips? I have worked with JSON that's just a straight array, but this is like a nested array, so a little more complex? How would one access these within PowerApps?

 

{
    "objectReference": "DPEndPointRegistration",
    "gatewayRequest": {
        "requestId": "d9b07e2d-865e-43ae-979d-b9430e7bac35",
        "functionName": "InSite-datagw-stack-GetTableResponse-16DISNZHJKT25",
        "responseInformation": "Response OK"
    },
    "queryResults": {
        "result": [
            {
                "InternalMachineId": 206,
                "StoreGroup": "202",
                "MachineType": "BASE",
                "MachineName": "P202B001",
                "PosNumber": 0,
                "LastUpdated": "2019-03-07T12:55:23.87"
            },
            {
                "InternalMachineId": 2,
                "StoreGroup": "201",
                "MachineType": "BASE",
                "MachineName": "P201S001",
                "PosNumber": 0,
                "LastUpdated": "2019-03-07T13:24:42.66"
            },
            {
                "InternalMachineId": 3,
                "StoreGroup": "201",
                "MachineType": "APP",
                "MachineName": "P201S001",
                "PosNumber": 0,
                "LastUpdated": "2019-03-07T13:24:42.66"
            },
            {
                "InternalMachineId": 4,
                "StoreGroup": "201",
                "MachineType": "POS",
                "MachineName": "P201T001",
                "PosNumber": 1,
                "LastUpdated": "2018-05-23T13:18:57.77"
            },
            {
                "InternalMachineId": 5,
                "StoreGroup": "394",
                "MachineType": "BASE",
                "MachineName": "P394S001",
                "PosNumber": 0,
                "LastUpdated": "2019-03-07T13:24:09.83"
            },
            {
                "InternalMachineId": 6,
                "StoreGroup": "394",
                "MachineType": "APP",
                "MachineName": "P394S001",
                "PosNumber": 0,
                "LastUpdated": "2019-03-07T13:24:09.83"
            },
            {
                "InternalMachineId": 7,
                "StoreGroup": "394",
                "MachineType": "POS",
                "MachineName": "P394T001",
                "PosNumber": 1,
                "LastUpdated": "2019-03-07T13:24:50.817"
            },
            {
                "InternalMachineId": 11,
                "StoreGroup": "777",
                "MachineType": "BASE",
                "MachineName": "P777B001",
                "PosNumber": 0,
                "LastUpdated": "2019-03-07T13:26:37.817"
            },
            {
                "InternalMachineId": 12,
                "StoreGroup": "777",
                "MachineType": "APP",
                "MachineName": "P777S001",
                "PosNumber": 0,
                "LastUpdated": "2019-03-07T13:27:44.463"
            },
            {
                "InternalMachineId": 13,
                "StoreGroup": "777",
                "MachineType": "POS",
                "MachineName": "P777T001",
                "PosNumber": 1,
                "LastUpdated": "2019-03-06T14:08:43.893"
            },
            {
                "InternalMachineId": 14,
                "StoreGroup": "399",
                "MachineType": "BASE",
                "MachineName": "P399S001",
                "PosNumber": 0,
                "LastUpdated": "2019-03-07T13:26:43.43"
            },
            {
                "InternalMachineId": 15,
                "StoreGroup": "399",
                "MachineType": "APP",
                "MachineName": "P399S001",
                "PosNumber": 0,
                "LastUpdated": "2019-03-07T13:26:43.43"
            },
            {
                "InternalMachineId": 16,
                "StoreGroup": "399",
                "MachineType": "POS",
                "MachineName": "P399T001",
                "PosNumber": 1,
                "LastUpdated": "2018-12-18T17:15:33.6"
            },
            {
                "InternalMachineId": 17,
                "StoreGroup": "303",
                "MachineType": "BASE",
                "MachineName": "P303B001",
                "PosNumber": 0,
                "LastUpdated": "2019-03-07T13:24:15.01"
            },
            {
                "InternalMachineId": 18,
                "StoreGroup": "303",
                "MachineType": "APP",
                "MachineName": "P303S001",
                "PosNumber": 0,
                "LastUpdated": "2019-03-07T13:27:49.65"
            },
            {
                "InternalMachineId": 19,
                "StoreGroup": "303",
                "MachineType": "POS",
                "MachineName": "P303T001",
                "PosNumber": 1,
                "LastUpdated": "2019-03-07T13:24:37.517"
            },
            {
                "InternalMachineId": 20,
                "StoreGroup": "321",
                "MachineType": "BASE",
                "MachineName": "P321B001",
                "PosNumber": 0,
                "LastUpdated": "2019-03-07T13:23:37.303"
            },
            {
                "InternalMachineId": 8,
                "StoreGroup": "471",
                "MachineType": "APP",
                "MachineName": "P999S001",
                "PosNumber": 0,
                "LastUpdated": "2019-03-07T13:25:21.7"
            },
            {
                "InternalMachineId": 9,
                "StoreGroup": "471",
                "MachineType": "BASE",
                "MachineName": "P471B001",
                "PosNumber": 0,
                "LastUpdated": "2019-03-07T13:25:06.2"
            },
            {
                "InternalMachineId": 10,
                "StoreGroup": "471",
                "MachineType": "POS",
                "MachineName": "P999T001",
                "PosNumber": 1,
                "LastUpdated": "2019-03-07T13:25:50.88"
            },
            {
                "InternalMachineId": 21,
                "StoreGroup": "399",
                "MachineType": "POS",
                "MachineName": "P399T002",
                "PosNumber": 2,
                "LastUpdated": "2019-03-07T13:23:44.337"
            },
            {
                "InternalMachineId": 345,
                "StoreGroup": "999",
                "MachineType": "APP",
                "MachineName": "P999S001",
                "PosNumber": 0,
                "LastUpdated": "2019-03-07T13:25:21.7"
            },
            {
                "InternalMachineId": 346,
                "StoreGroup": "999",
                "MachineType": "APP",
                "MachineName": "P999S001",
                "PosNumber": 0,
                "LastUpdated": "2019-03-07T13:25:21.7"
            },
            {
                "InternalMachineId": 37,
                "StoreGroup": "295",
                "MachineType": "APP",
                "MachineName": "P295S001",
                "PosNumber": 0,
                "LastUpdated": "2018-09-21T01:38:31.717"
            },
            {
                "InternalMachineId": 38,
                "StoreGroup": "770",
                "MachineType": "BASE",
                "MachineName": "P770B001",
                "PosNumber": 0,
                "LastUpdated": "2018-05-23T13:27:35.327"
            },
            {
                "InternalMachineId": 39,
                "StoreGroup": "770",
                "MachineType": "APP",
                "MachineName": "P770S001",
                "PosNumber": 0,
                "LastUpdated": "2018-05-23T13:44:46.867"
            },
            {
                "InternalMachineId": 40,
                "StoreGroup": "479",
                "MachineType": "APP",
                "MachineName": "P479S001",
                "PosNumber": 0,
                "LastUpdated": "2019-02-13T10:36:07.62"
            },
            {
                "InternalMachineId": 41,
                "StoreGroup": "770",
                "MachineType": "POS",
                "MachineName": "P770T001",
                "PosNumber": 1,
                "LastUpdated": "2018-05-23T13:42:01.927"
            },
            {
                "InternalMachineId": 47,
                "StoreGroup": "770",
                "MachineType": "POS",
                "MachineName": "P770T002",
                "PosNumber": 2,
                "LastUpdated": "2018-05-23T21:37:27.96"
            },
            {
                "InternalMachineId": 204,
                "StoreGroup": "321",
                "MachineType": "POS",
                "MachineName": "P321T001",
                "PosNumber": 1,
                "LastUpdated": "2019-03-07T13:27:20.373"
            },
            {
                "InternalMachineId": 205,
                "StoreGroup": "321",
                "MachineType": "APP",
                "MachineName": "P321S001",
                "PosNumber": 0,
                "LastUpdated": "2019-03-07T13:25:23.507"
            },
            {
                "InternalMachineId": 207,
                "StoreGroup": "202",
                "MachineType": "APP",
                "MachineName": "P202S001",
                "PosNumber": 0,
                "LastUpdated": "2019-03-07T13:22:18.937"
            },
            {
                "InternalMachineId": 208,
                "StoreGroup": "399",
                "MachineType": "POS",
                "MachineName": "P399T003",
                "PosNumber": 3,
                "LastUpdated": "2019-03-07T13:25:25.35"
            },
            {
                "InternalMachineId": 46,
                "StoreGroup": "770",
                "MachineType": "POS",
                "MachineName": "P770T004",
                "PosNumber": 4,
                "LastUpdated": "2018-05-22T18:50:46.06"
            },
            {
                "InternalMachineId": 48,
                "StoreGroup": "770",
                "MachineType": "POS",
                "MachineName": "P770T003",
                "PosNumber": 3,
                "LastUpdated": "2018-05-23T21:43:08.27"
            },
            {
                "InternalMachineId": 343,
                "StoreGroup": "C2A",
                "MachineType": "AWSMASTER",
                "MachineName": "EC2AMAZ-FFCI5O0",
                "PosNumber": 0,
                "LastUpdated": "2019-02-22T09:04:54.903"
            },
            {
                "InternalMachineId": 344,
                "StoreGroup": "C2A",
                "MachineType": "AWSMASTER",
                "MachineName": "EC2AMAZ-SLGAJ85",
                "PosNumber": 0,
                "LastUpdated": "2019-02-22T09:06:54.303"
            }
        ]
    }
}
9 REPLIES 9
Super User II
Super User II

I'm interested to see what others would do in this situation, so I'm going to comment with the concept of what I'd do, which I don't think is the most efficient way to do it and I haven't tested it.

 

Crazy inefficient way:

Pass that data to Flow,
Initialize variable,
Compose Substring of second indexof { -1 and of last } -1 so we lose the last } and keep the second {

Compose Split by },

Use IndexOf and then the name of the property to create strings of the data items.

Send data back to PowerApps from the Flow

 

Structured way:

Send the data to Flow,

Parse the entire original data to JSON,

Do a loop through each item to pull out its properties then either send that back or compose it into a larger piece of data.

Send that back to PowerApps

 

John Liu's piece on parsing JSON with Flow might be very useful to you, so here's the link
http://johnliu.net/blog/2018/6/a-thesis-on-the-parse-json-action-in-microsoft-flow

 

Would then probably expand on that depending on what I needed.

 

Anyone else got some good ideas on how to handle this?


@iAm_ManCat

Please 'Mark as Solution' if someone's post answered your question and always 'Thumbs Up' the posts you like or that helped you!


Thanks!
You and everyone else in the community make it the awesome and welcoming place it is, keep your questions coming and make sure to 'like' anything that makes you 'Appy
Sancho Harker, MVP


Community Support
Community Support

HI @JamesM ,

Could you please share a bit more about your scenario?

Do you mean that the response your custom connector returns is the json data that you mentioned?

Further, could you please share a bit more about the JSON output data within your app? Could you please share a screenshot about it?

 

I have made a test on my side, please take a try with the following workaround:

Add a Data Table control (Or Gallery control) within your app, set the Items property to following:

YourCustomConnector.Action(...).queryResults.result

Note: The Action(...) represents the operation you executed from your custom connector.

then check if the data is populated within your Data table control.

You could also consider take a try with the following workaorund:

Set the OnSelect property of a Button to following:

ClearCollect(ResultCollection, YourCustomConnector.Action(...).queryResults.result)

check if the data is populated within the ResultCollection.

 

In addition, you could also consider take a try to trigger/fire a flow from your app, and execute your custom connector action within Microsoft Flow, and then send the Table result (queryResults.Result) back to your app.

I have made a test on my side, please take a try with the following workaround:

Flow's configuration as below:6.JPG

 

7.JPG

Within the Compose action, Inputs field set to the JSON Data that you mentioned.

Within the "Initialize variable" action, Name field set to ArrayData, Type set to Array and Value set to following formula:

outputs('Compose')?['queryResults']?['result']

Within the "Response" action, Body field set to ArrayData variable. Set the Response Body JSON Schema field to following formula:

{
    "type": "array",
    "items": {
        "type": "object",
        "properties": {
            "InternalMachineId": {
                "type": "integer"
            },
            "StoreGroup": {
                "type": "string"
            },
            "MachineType": {
                "type": "string"
            },
            "MachineName": {
                "type": "string"
            },
            "PosNumber": {
                "type": "integer"
            },
            "LastUpdated": {
                "type": "string"
            }
        },
        "required": [
            "InternalMachineId",
            "StoreGroup",
            "MachineType",
            "MachineName",
            "PosNumber",
            "LastUpdated"
        ]
    }
}

App's configuration as below:8.JPG

Set the OnSelect property of the "Trigger Flow" button to following:

ClearCollect(ArrayData, '20190308_case9'.Run())

On your side, you should type:

ClearCollect(ArrayData, 'YourFlowName'.Run())

The ArrayData populated with data as below:9.JPG

More details about starting flow from an app, please check the following article or video:

https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/using-logic-flows

https://www.youtube.com/watch?v=1wl9AtxWdkg

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thanks for posting this Kris, I like the idea of sending it back as a table via an array, very neat - I hadn't considered this before!


@iAm_ManCat

Please 'Mark as Solution' if someone's post answered your question and always 'Thumbs Up' the posts you like or that helped you!


Thanks!
You and everyone else in the community make it the awesome and welcoming place it is, keep your questions coming and make sure to 'like' anything that makes you 'Appy
Sancho Harker, MVP


Hi @v-xida-msft thanks for your response. I'll look into this today. Question however, are you saying that I am not limited to responding to powerapps with data via the 'Respond to PowerApps' flow action? That you can in fact respond with output from a HTTP/HTTPS call without needing to say add it to the 'text' or 'file' or 'email' respond to PowerApps action? I wasn't aware of that!

@v-xida-msft Should I expect to see some form of body in my final response? It appears empty: 

 

2019-03-09 09_17_39-Run History _ Microsoft Flow.png2019-03-09 09_18_01-Run History _ Microsoft Flow.png2019-03-09 09_18_15-Run History _ Microsoft Flow.png2019-03-09 09_18_28-Run History _ Microsoft Flow.png

Never mind, that empty response was my fault - stupid me mixing up my JSON schemas :). 


No, actually it's still not working. I seem to be getting the 'schema' back into PowerApps, as the columns are there, but no data. 

 

In Flow: 

 

2019-03-09 09_18_28-Run History _ Microsoft Flow.png

 

In PowerApps

2019-03-09 09_36_49-SpotLight - Saved (Unpublished) - PowerApps.png

Hello, many times when you are taking the JSON and deriving the schema from sample JSON response, Flow and LogicApps don't like Null values. We always default our JSON responses with null if there is no value however, Flow and LogicApps don't like it. Therefore, take your sample response from the API, use something like VS Code and do a find and replace and replace "Null" with "" and add that sample data to your flow or LogicApp. 

 

Once complete test it and it should work.

Instead of collecting the initial response, collect the array seperately and you will be able to access the proerties directly.

 

Power Apps example

ClearCollect(results, CustomConnector.Action().results)

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 (15,022)