cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
PowerAppsDaniel
Level: Powered On

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
Super User
Super User

Re: Recover JSON column from SQL as PowerApps collection

Hi @PowerAppsDaniel 

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-... 

View solution in original post

2 REPLIES 2
Super User
Super User

Re: Recover JSON column from SQL as PowerApps collection

Hi @PowerAppsDaniel 

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-... 

View solution in original post

PowerAppsDaniel
Level: Powered On

Re: Recover JSON column from SQL as PowerApps collection

Hello @timl,

 

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

 

Thanks!

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors (Last 30 Days)
Users online (6,911)