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
Solved! Go to Solution.
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.
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.
Hello @timl,
Could you please provide more details (or reference) about the Flow workaround?
Thanks!
User | Count |
---|---|
139 | |
132 | |
79 | |
74 | |
74 |
User | Count |
---|---|
207 | |
196 | |
70 | |
62 | |
55 |