top of page
Writer's pictureJon Russell

Retrieve values as a concatenated string from JSON object

Updated: Apr 30, 2023


No not that JASON !


How are you doing?


I was on the Power Automate forums today and came across this post:



I thought I would write a quick blog post to explain what I did to achieve the intended result.


The poster, was asking for a value from a JSON array to be extracted and then concatenated into a string.


First of all, I set up an Instant Cloud flow, then I created a StringValue string variable in an initialize variable step. Next, I added a compose action to capture the JSON object from the post on the forums. Note: I came up across an error when trying to save the flow, I needed to add an extra @ sign at the start of the odata.type lines.



Next, I used the Select action, and pulled out the Value item from the JSON object. In the screenshot below, I am selecting the Ouputs from the dynamic content from the compose step and then mapping the column "Value" to the value item from the JSON object.


You'll need to write an expression for this to get this, but it will change and resolve to Value as shown in the screenshot below. That expression is item()?['Value']



After this, we need to set the StringValue variable to join each of the values from the Select statement into one string, this is done by using the following expression: join(body('Select'),',')



The result of this is:


{"Value":"Boundary Wall"},{"Value":"Tower "},{"Value":"BTS/DG PAD"}


We now need to use a final compose step to use the replace expression, a couple of times to tidy this string up:


You can do this in one compose really. The first part is to replace the {"Value":" with nothing and then run the replace again to remove the "}".


This can be achieved by:


replace(replace(variables('StringValue'),'{"Value":"',''),'"}','')



When this flow runs, it looks like this:





I hope this helps anyone facing this issue, thanks !


EDIT


My good friend Paul Murana commented on my LinkedIn share of this post here, he said that instead of doing the Select step, like I have done it we can simply do this instead:




Thanks a lot for that Paul, always learning !

3,233 views0 comments

Comentarios


bottom of page