cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

Recover JSON column from SQL as PowerApps collection

Hello PowerApps Community!

 

Is there a way of parsing a JSON object in a column from an SQL Server database to a collection in PowerApps?

 

I generated the JSON object using the JSON function with data from a collection, but now I want to retrieve the object from the database and revert the process.

 

Right now the JSON in the SQL column looks like this:

 

 

[{"Active":true,"Name":"Option_1"},{"Active":true,"Name":"Option_2"},{"Active":true,"Name":"Option_3"},{"Active":true,"Name":"Option_4"}]

 

 

And I need it in a collection with the same fields (Active and Name). The alternative would be to have 4 additional columns in the table, but I really want to avoid that, as it will probably need to scale in the future without adding columns to the table.

 

EDIT UPDATE:

As of right now, I managed to edit the text value (hard-coding but it's fine). However, when ClearCollect it detects it as text and doesn't create the collection as it should. 

This works (copying and pasting the result from the edited SQL Server column):

ClearCollect(ColTest; {Active:true;Name:"Option_1"};{Active:true;Name:"Option_2"};{Active:true;Name:"Option_3"};{Active:true;Name:"Option_4"})

This doesn't work:

ClearCollect(ColTest; JSONText)

// JSONText = "{Active:true;Name:"Option_1"};{Active:true;Name:"Option_2"};{Active:true;Name:"Option_3"};{Active:true;Name:"Option_4"}"

I know it is because it is taking it as a string, is there a way to avoid that?

 

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
timl
Super User III
Super User III

Hi @Anonymous 

Unfortunately, there's currently no way to do this in PowerApps.

There's a post in the ideas forum about this. You can vote on this and hopefully MS will add the feature in a future release.

https://powerusers.microsoft.com/t5/PowerApps-Ideas/Parse-JSON-in-PowerApps/idi-p/359563 

The typical workaround is to use Flow to do this. 

Since you're using SQL Server, another approach would be to create a SQL View, and to use the functions in SQL Server to reconstitute your JSON into a recordset.

https://docs.microsoft.com/en-us/sql/relational-databases/json/json-data-sql-server?view=sql-server-ver15 

View solution in original post

2 REPLIES 2
timl
Super User III
Super User III

Hi @Anonymous 

Unfortunately, there's currently no way to do this in PowerApps.

There's a post in the ideas forum about this. You can vote on this and hopefully MS will add the feature in a future release.

https://powerusers.microsoft.com/t5/PowerApps-Ideas/Parse-JSON-in-PowerApps/idi-p/359563 

The typical workaround is to use Flow to do this. 

Since you're using SQL Server, another approach would be to create a SQL View, and to use the functions in SQL Server to reconstitute your JSON into a recordset.

https://docs.microsoft.com/en-us/sql/relational-databases/json/json-data-sql-server?view=sql-server-ver15 

View solution in original post

Anonymous
Not applicable

Hello @timl,

 

Could you please provide more details (or reference) about the Flow workaround? 

 

Thanks!

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

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 (27,004)