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

Collect JSON string into columns

Good evening,

 

I have this JSON string returned from Microsoft Automate and I'd like to turn the results into columns. The sample return string looks like this:

 

 

{"__metadata":{"id":"123","uri":"api/Items(1)","etag":"\"1\"","type":"SP.Data.SP.Items"},"Title":"TitleVal","Column1":"Column1Val","SomeOtherCol":"SomeOtherColVal","UserID":"1697"}

 

 

I know I only want the string just after the first "}" and so I generate this code:

 

 

Last(FirstN(Split(sampleString.Text, "}"), 2)).Result

 

 

From here, what is the best method to converting the result from this:
sample_start.png

into a collection with this:

TitleColumn1SomeOtherColUserID
TitleValColumn1ValSomeOtherColVal1697

 

The logic that I think may work is to to not even do a split yet and conduct a find for each field and then split after to find the values for it. I'm just bouncing ideas here and see if I'm working in the right direction.

EDIT: I got this and it's giving me the correct results but I'm kinda hardcoding the number of spaces to retrieve. There's got to be a better / dynamic way.

 

Substitute(First(Split(Mid(sampleString.Text, Find("SomeOtherCol", sampleString.Text) + 13 +1), ",")).Result, Char(34), Blank())


EDIT #2: I think I am going to settle with this logic:

Substitute(Last(Split(First(Split(Mid(sampleString.Text,Find("Title",sampleString.Text)),",")).Result,":")).Result, Char(34), Blank())

 

1 ACCEPTED SOLUTION

Accepted Solutions
v-xida-msft
Community Support
Community Support

Hi @MrNguyen ,

Have you solved your problem?

 

Based on the needs that you mentioned, actually, you could consider convert the JSON String into the JSON Table, then pass the JSON Table back to your canvas app.

 

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

Flow's configuration as below:

1.JPG

Add a "Response" action at the bottom of your flow, set the Body field to following:

json(variables('JSONString'))

Note: Use the json expression to convert the JSON String into JSON Table

 

Set the "Response Body JSON Schema" field to following:

{
    "type": "object",
    "properties": {
        "__metadata": {
            "type": "object",
            "properties": {
                "id": {
                    "type": "string"
                },
                "uri": {
                    "type": "string"
                },
                "etag": {
                    "type": "string"
                },
                "type": {
                    "type": "string"
                }
            }
        },
        "Title": {
            "type": "string"
        },
        "Column1": {
            "type": "string"
        },
        "SomeOtherCol": {
            "type": "string"
        },
        "UserID": {
            "type": "string"
        }
    }
}

 

App's configuration as below:

2.JPG

Set the OnSelect property of the "Retrieve Collection" button to following:

ClearCollect(TableResult, 'PowerApp->Initializevariable,Response'.Run())

The TableResult collection would look like below:

3.JPG

 

Please check and see if the following blog would help in your scenario (Pass table from flow to canvas app):

https://powerapps.microsoft.com/en-us/blog/return-an-array-from-flow-to-powerapps-response-method/

 

Please take a try with above solution, then check if the issue is solved. If the solution above is helpful in your scenario, or you have solved your problem, please consider go ahead to click "Accept as Solution" to identify this thread has been solved.

 

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.

View solution in original post

4 REPLIES 4
royg
Advocate I
Advocate I

If you have control over the Power Automate Flow that your app is using, you could return the JSON object instead of the result string so your app can consume the result as a collection/object without parsing it. Try adding a Response action (Premium) and place your JSON text into the Schema builder. 

hehe, unfortunately I am not allowed to consume any premium connectors, but taking a bit of your idea, I might sanitize the data before consuming it inside PowerApps. 

v-xida-msft
Community Support
Community Support

Hi @MrNguyen ,

Have you solved your problem?

 

Based on the needs that you mentioned, actually, you could consider convert the JSON String into the JSON Table, then pass the JSON Table back to your canvas app.

 

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

Flow's configuration as below:

1.JPG

Add a "Response" action at the bottom of your flow, set the Body field to following:

json(variables('JSONString'))

Note: Use the json expression to convert the JSON String into JSON Table

 

Set the "Response Body JSON Schema" field to following:

{
    "type": "object",
    "properties": {
        "__metadata": {
            "type": "object",
            "properties": {
                "id": {
                    "type": "string"
                },
                "uri": {
                    "type": "string"
                },
                "etag": {
                    "type": "string"
                },
                "type": {
                    "type": "string"
                }
            }
        },
        "Title": {
            "type": "string"
        },
        "Column1": {
            "type": "string"
        },
        "SomeOtherCol": {
            "type": "string"
        },
        "UserID": {
            "type": "string"
        }
    }
}

 

App's configuration as below:

2.JPG

Set the OnSelect property of the "Retrieve Collection" button to following:

ClearCollect(TableResult, 'PowerApp->Initializevariable,Response'.Run())

The TableResult collection would look like below:

3.JPG

 

Please check and see if the following blog would help in your scenario (Pass table from flow to canvas app):

https://powerapps.microsoft.com/en-us/blog/return-an-array-from-flow-to-powerapps-response-method/

 

Please take a try with above solution, then check if the issue is solved. If the solution above is helpful in your scenario, or you have solved your problem, please consider go ahead to click "Accept as Solution" to identify this thread has been solved.

 

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.

View solution in original post

@v-xida-msft ,

Thanks very much for this! I have yet to test this out since it uses a premium connector but I will save it and attempt it later if company allows me hehehe.

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Power Apps June 2021

June Power Apps Community Call

Don't miss the call this month on June 16th - 8a PDT

Top Solution Authors
Top Kudoed Authors
Users online (10,187)