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 II
Advocate II

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
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Top Kudoed Authors
Users online (1,592)