{"id":316,"date":"2018-07-24T19:29:00","date_gmt":"2018-07-25T01:29:00","guid":{"rendered":"http:\/\/draith.com\/?p=316"},"modified":"2018-07-24T19:29:00","modified_gmt":"2018-07-25T01:29:00","slug":"logic-apps-or-flow-string-to-array","status":"publish","type":"post","link":"https:\/\/draith.com\/?p=316","title":{"rendered":"Logic Apps or Flow &#8211; String to Array"},"content":{"rendered":"<p>Ran across an interesting problem today &#8211; how to, in Flow or Logic Apps, take a string and create a data array from it.  In this particular instance, the bit of data was being emailed to an Outlook.com inbox, and we wanted to parse that data and only work with 3 pieces of the string.  It sounds easy, as actually is, but takes a small bit of knowledge ahead of time.  Hopefully this helps you avoid some web-searches.<\/p>\n<p>So let&#8217;s say we have some data formatted like this:<\/p>\n<pre class=\"lang:default decode:true \" >[\"f8c8e13b-48be-4a91-818e-c6fasdfd001\",\"OM.DEMO\",\"Processor\",\"% Processor Time\",\"1\",45.9060745239258,\"2018-07-17T19:46:55.577Z\",\"OpsManager12\",\"\\\\\\\\OM.DEMO\\\\Processor(1)\\\\% Processor Time\",\"d88f095c-8bf8-4e88-d827-663fe6asdf01\",null,null,null,null,null,null,\"Perf\"]<\/pre>\n<p>This data is a sample performance metric &#8211; something you might receive from Log Analytics, for example.  This data is obviously an array in theory, but right now it&#8217;s just a long string to Flow or Logic Apps.  So, let&#8217;s get this into a usable array and access only the bits we want.<\/p>\n<p>Here is the email:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/draith.com\/wp-content\/uploads\/2018\/07\/sta-email.png\" alt=\"\" width=\"2382\" height=\"334\" class=\"alignnone size-full wp-image-317\" srcset=\"\/wp-content\/uploads\/2018\/07\/sta-email.png 2382w, \/wp-content\/uploads\/2018\/07\/sta-email-300x42.png 300w, \/wp-content\/uploads\/2018\/07\/sta-email-1024x144.png 1024w, \/wp-content\/uploads\/2018\/07\/sta-email-768x108.png 768w, \/wp-content\/uploads\/2018\/07\/sta-email-1536x215.png 1536w, \/wp-content\/uploads\/2018\/07\/sta-email-2048x287.png 2048w, \/wp-content\/uploads\/2018\/07\/sta-email-1568x220.png 1568w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/p>\n<p>Now, let&#8217;s create a trigger and add a &#8220;Compose&#8221; action.  There is literally no configuration to the &#8220;Compose&#8221; action.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/draith.com\/wp-content\/uploads\/2018\/07\/sta-compose.png\" alt=\"\" width=\"1034\" height=\"435\" class=\"alignnone size-full wp-image-318\" srcset=\"\/wp-content\/uploads\/2018\/07\/sta-compose.png 1034w, \/wp-content\/uploads\/2018\/07\/sta-compose-300x126.png 300w, \/wp-content\/uploads\/2018\/07\/sta-compose-1024x431.png 1024w, \/wp-content\/uploads\/2018\/07\/sta-compose-768x323.png 768w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/p>\n<p>Next, initialize a variable and set it&#8217;s type to an Array.  Set the value to the output of the &#8220;Compose&#8221; action.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/draith.com\/wp-content\/uploads\/2018\/07\/sta-variable.png\" alt=\"\" width=\"1019\" height=\"692\" class=\"alignnone size-full wp-image-319\" srcset=\"\/wp-content\/uploads\/2018\/07\/sta-variable.png 1019w, \/wp-content\/uploads\/2018\/07\/sta-variable-300x204.png 300w, \/wp-content\/uploads\/2018\/07\/sta-variable-768x522.png 768w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/p>\n<p>From here, you can call the individual instances of the array in a very straight forward method.  You simple reference the index of the item you want like this:  variables(&#8216;StringArray&#8217;)[1]     (This would return the second item in the array since the array numbering starts at 0).  In this example, I pull out three pieces of data, and (for no particular reason) email it back to myself.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/draith.com\/wp-content\/uploads\/2018\/07\/sta-output.png\" alt=\"\" width=\"1610\" height=\"652\" class=\"alignnone size-full wp-image-320\" srcset=\"\/wp-content\/uploads\/2018\/07\/sta-output.png 1610w, \/wp-content\/uploads\/2018\/07\/sta-output-300x121.png 300w, \/wp-content\/uploads\/2018\/07\/sta-output-1024x415.png 1024w, \/wp-content\/uploads\/2018\/07\/sta-output-768x311.png 768w, \/wp-content\/uploads\/2018\/07\/sta-output-1536x622.png 1536w, \/wp-content\/uploads\/2018\/07\/sta-output-1568x635.png 1568w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/p>\n<p>And the email:<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/draith.com\/wp-content\/uploads\/2018\/07\/sta-emailoutput.png\" alt=\"\" width=\"1012\" height=\"388\" class=\"alignnone size-full wp-image-322\" srcset=\"\/wp-content\/uploads\/2018\/07\/sta-emailoutput.png 1012w, \/wp-content\/uploads\/2018\/07\/sta-emailoutput-300x115.png 300w, \/wp-content\/uploads\/2018\/07\/sta-emailoutput-768x294.png 768w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Ran across an interesting problem today &#8211; how to, in Flow or Logic Apps, take a string and create a data array from it. In this particular instance, the bit of data was being emailed to an Outlook.com inbox, and we wanted to parse that data and only work with 3 pieces of the string. &hellip; <a href=\"https:\/\/draith.com\/?p=316\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Logic Apps or Flow &#8211; String to Array&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-316","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/draith.com\/index.php?rest_route=\/wp\/v2\/posts\/316","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/draith.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/draith.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/draith.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/draith.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=316"}],"version-history":[{"count":0,"href":"https:\/\/draith.com\/index.php?rest_route=\/wp\/v2\/posts\/316\/revisions"}],"wp:attachment":[{"href":"https:\/\/draith.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=316"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/draith.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=316"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/draith.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=316"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}