{"id":32895,"date":"2022-10-21T11:27:46","date_gmt":"2022-10-21T05:57:46","guid":{"rendered":"https:\/\/www.inogic.com\/blog\/?p=32895"},"modified":"2022-12-02T17:39:05","modified_gmt":"2022-12-02T12:09:05","slug":"parsing-json-string-into-a-json-object-using-parsejson-function-in-canvas-app-within-power-platform","status":"publish","type":"post","link":"https:\/\/www.inogic.com\/blog\/2022\/10\/parsing-json-string-into-a-json-object-using-parsejson-function-in-canvas-app-within-power-platform\/","title":{"rendered":"Parsing JSON string into a JSON object using ParseJSON() function in Canvas App within Power Platform"},"content":{"rendered":"<p>A few months ago we published one of our <a href=\"https:\/\/www.inogic.com\/blog\/2022\/03\/parse-json-in-canvas-app-using-regex\/\" target=\"_blank\" rel=\"noopener\">blogs<\/a> to parse the JSON string using regular expression. As per the blog, to parse the JSON string into JSON object we have to format the JSON string into regular expression format as shown below:<\/p>\n<p><strong><em>&#8220;\\{&#8220;&#8221;id&#8221;&#8221;:&#8221;&#8221;(?&lt;id&gt;[^&#8221;&#8221;]*)&#8221;&#8221;,&#8221;&#8221;name&#8221;&#8221;:&#8221;&#8221;(?&lt;name&gt;[^&#8221;&#8221;]*)&#8221;<\/em><\/strong><\/p>\n<p>Now, we can directly parse JSON string using <strong><em>ParseJSON()<\/em><\/strong> function, so there is no need to format string into the regular expression to parse JSON.<\/p>\n<p>To parse JSON string using <strong><em>ParseJSON() <\/em><\/strong>function, you have to enable the \u201cParse JSON function and untyped object\u201d within upcoming features of the Canvas App. If you have not enabled this in the upcoming feature then <strong><em>ParseJSON() <\/em><\/strong>function will not work in your canvas app. To enable this feature Go to Settings&gt; Click on the \u201cUpcoming Features\u201d tab &gt; Search \u201cParseJSON function\u201d keyword in the search box &gt; Enable the \u201cParse JSON function and untyped object\u201d feature as shown in the screenshot below:<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-32897\" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/10\/1Canvas-App.jpeg\" alt=\"\" width=\"1361\" height=\"651\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/10\/1Canvas-App.jpeg 1361w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/10\/1Canvas-App-300x143.jpeg 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/10\/1Canvas-App-1024x490.jpeg 1024w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/10\/1Canvas-App-768x367.jpeg 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/10\/1Canvas-App-660x316.jpeg 660w\" sizes=\"(max-width: 1361px) 100vw, 1361px\" \/><\/p>\n<p>Please find the below syntax and example of the <strong><em>ParseJSON()<\/em><\/strong> function:<\/p>\n<p><strong>Syntaxt:<\/strong><\/p>\n<p><strong><em>ParseJSON(JSON_STRING)<\/em><\/strong><\/p>\n<p>Where,<\/p>\n<p>JSON_STRING \u2013 It strings in JSON format as shown below:<\/p>\n<p>\u201c{\u201cid\u201d:\u201d958788BD-DA0A-4859-9788-13509BC29D7B\u201d,\u201d name\u201d:\u201d Basic User\u201d}\u201d<\/p>\n<p><strong>Example:<\/strong><\/p>\n<p>We have created a Canvas App where we want to read the security role of the user from JSON string as shown below. When the user clicks on the \u201cConvert to JSON\u201d button a power FX expression executes. It will read the JSON string that the user enters in the first text box and converts that JSON string into a JSON object and returns the value which is associated with the \u201cname\u201d key in the JSON string. Finally, it displays the output in label control which is highlighted in the screenshot below.<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-32896\" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/10\/2Canvas-App.jpeg\" alt=\"\" width=\"1365\" height=\"649\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/10\/2Canvas-App.jpeg 1365w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/10\/2Canvas-App-300x143.jpeg 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/10\/2Canvas-App-1024x487.jpeg 1024w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/10\/2Canvas-App-768x365.jpeg 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/10\/2Canvas-App-660x314.jpeg 660w\" sizes=\"(max-width: 1365px) 100vw, 1365px\" \/><\/p>\n<p>Please find the below power FX expression which executes on click of the \u201cConvert to JSON\u201d button:<\/p>\n<p><strong><em>Set(txtValue,Text( ParseJSON(jsonstringtb.Text).name ))<\/em><\/strong><\/p>\n<p>Please find the below data types in the Canvas App and their JSON string and also how we can parse those strings.<\/p>\n<p>1. Boolean:<\/p>\n<p>{\u201cflag\u201d: true}<\/p>\n<p>Boolean( ParseJSON(&#8220;{ &#8220;flag&#8221;: true }&#8221;).flag )<\/p>\n<p>2. Currency and Number<\/p>\n<p>{ &#8220;value&#8221;: 65.6 }<\/p>\n<p>Value( ParseJSON(&#8220;{ &#8220;value&#8221;: 65.6 }&#8221;).value )<\/p>\n<p>3. Date, DateTime, and Time<\/p>\n<p>{ &#8220;Date&#8221;: &#8220;10-19-2022&#8221; }<\/p>\n<p>DateValue( ParseJSON(&#8220;{ &#8220;date&#8221;: &#8220;2022-05-10&#8243;}&#8221;).date )<\/p>\n<h2><strong>Conclusion<\/strong><\/h2>\n<p>Using <strong><em>ParseJSON()<\/em><\/strong> function we can easily parse the JSON string to a JSON object and retrieve any value from a converted JSON object. <u><\/u><\/p>\n<p><a href=\"https:\/\/www.inogic.com\/blog\/2022\/10\/integrate-microsoft-dynamics-365-customer-engagement-and-sharepoint-with-smart-document-management-and-security-model-sync\/\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" class=\"alignnone size-full wp-image-32898\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/10\/Gamifics365.png\" alt=\"\" width=\"800\" height=\"200\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/10\/Gamifics365.png 800w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/10\/Gamifics365-300x75.png 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/10\/Gamifics365-768x192.png 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/10\/Gamifics365-660x165.png 660w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>A few months ago we published one of our blogs to parse the JSON string using regular expression. As per the blog, to parse the JSON string into JSON object we have to format the JSON string into regular expression format as shown below: &#8220;\\{&#8220;&#8221;id&#8221;&#8221;:&#8221;&#8221;(?&lt;id&gt;[^&#8221;&#8221;]*)&#8221;&#8221;,&#8221;&#8221;name&#8221;&#8221;:&#8221;&#8221;(?&lt;name&gt;[^&#8221;&#8221;]*)&#8221; Now, we can directly parse JSON string using ParseJSON() function,\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.inogic.com\/blog\/2022\/10\/parsing-json-string-into-a-json-object-using-parsejson-function-in-canvas-app-within-power-platform\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":13,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[18,2361],"tags":[],"class_list":["post-32895","post","type-post","status-publish","format-standard","hentry","category-dynamics-365-v9-2","category-technical"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/32895","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/comments?post=32895"}],"version-history":[{"count":0,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/32895\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/media?parent=32895"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/categories?post=32895"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/tags?post=32895"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}