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

How to parse JSON in PowerApps? OR How to get/set JSON data in SharePoint list column?

Hello Everyone,

 

I have stored data in JSON data under the SharePoint list "multiline and text" column. J needs to retrieve that JSON data on the PowerApp form and update that JSON data from the PowerApp form.

 

Can anyone suggest me for the same?

2 REPLIES 2
Nogueira1306
Community Champion
Community Champion

Check this 2 links:

 

 

https://powerusers.microsoft.com/t5/Building-Power-Apps/Parse-JSON-string-in-Power-APPS/td-p/381832 

 

https://powerusers.microsoft.com/t5/Power-Apps-Portals/How-to-parse-JSON-in-PowerApps/td-p/783737 

 

If you need additional help please tag me in your reply and please like my reply.
If my reply provided you with a solution, pleased mark it as a solution ✔️!

Best regards,
Gonçalo Nogueira

RandyHayes
Super User
Super User

@BJoshi 

Yes, but there is not a function in PowerApps to convert to data.

Take a look at this post - it was based more on API results, but the point was, it was JSON.  In that in the second message, I have a formula there that will convert JSON to data.  It is far superior than trying to do substitute functions and other string handling.  The only changes you need to make are on the column names.

 

From that post, the following formula is found:

Set(APIResultRecord,
    With({_apiResult: nametest.RunAPI({rxid: TestInput1_1.Text, format: TextInput1_2.Text}).Substances.data)},
        With({convertedJSON:
            ForAll(MatchAll(_apiResult, """(?<nvalue>[^""]+)"": *""?(?<jvalue>[^(""|\n)]+)""?").SubMatches,
                {Name:First(SubMatches).Value, Value:Last(SubMatches).Value}
            )},

        {uuid: LookUp(convertedJSON, Name="uuid", Value), 
         nsinchikey: LookUp(convertedJSON, Name="nsinchikey", Value),
         inchikey : LookUp(convertedJSON, Name="inchikey", Value),
         smiles: LookUp(convertedJSON, Name="smiles", Value),
         role: LookUp(convertedJSON, Name="role", Value)
        }
    )
)

 

I use that similar formula often to restore JSON data that is in a Multiline SharePoint columns.  I put a lot of user preferences in JSON in multiline columns.  To restore them from the JSON, I use the above formula with a slight variation.  Here is an example:

With({prefRecord: 
    LookUp(Apps, Title=glbAppInfo.AppName && UserEmail=glbAppInfo.EmailLower, Prefs)},

       With({convertedJSON:
           ForAll(MatchAll(prefRecord, """(?<nvalue>[^""]+)"": *""?(?<jvalue>[^(""|,|\n)]+)""?").SubMatches As ms,
               {Name:First(ms.SubMatches).Value, Value:Last(ms.SubMatches).Value}
           )},

           {
             FontSize : Value(LookUp(convertedJSON, Name="FontSize", Value)),
             ThemeName: LookUp(convertedJSON, Name="ThemeName", Value),
             ShowImages: (LookUp(convertedJSON, Name="ShowImages", Value) = "true"),
             Sort: {Column: LookUp(convertedJSON, Name="SortColumn", Value),
                    Order: Switch(LookUp(convertedJSON, Name="SortOrder", Value), 
                           "ascending", SortOrder.Ascending, SortOrder.Descending)
                    },
             ShowWallpaper: (LookUp(convertedJSON, Name="ShowWallpaper", Value) = "true"),
             Language: LookUp(glbAppInfo.Languages, Language=Coalesce(LookUp(convertedJSON, Name="Language", Value), "English"))                     
           }
       )
)

 The above converts a JSON string that has values for a 1 numeric, 2 text, 2 boolean and 1 complex elements of the JSON string.

 

There is actually more to that formula that I removed for clarity (the formula actually evaluates theme values as well, but I didn't want to overcomplicate for you purposes of example).

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

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 (2,007)