cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Mick282 Helper II
Helper II

How to combine a JSON array value and loop it into a single value to email out to people

Hi all,

 

So I've got a HTTP GET step setup to call a REST API which returns a JSON object. Within the object is an array of chat conversations. What I now want to do is, when the conversation is finished to combine all the array items but also set some <br> and <hr> tags between each part of the conversation so that it's well formatted. A sample of the JSON code is below:

 

"conversation": [
{
"type": "comment",
"body": "<p>Hi this is a comment</p>"
},
{
"type": "comment",
"body": "<p>How can I help you?</p>"
},
{
"type": "comment",
"body": "<p>I need HELP!</p>"
}
]

 

I want to combine the "body" portion of the conversation and include a <br> and <hr> tag after each "body" so the end result in a email message would be:

 

<p>Hi this is a comment</p><br><hr><p>How can I help you?</p><br><hr><p>I need HELP!</p>

 

So I've already parsed the returned JSON and just need a method to convert the dynamic content into a loopable single value with some additional HTML tags in between.

1 ACCEPTED SOLUTION

Accepted Solutions
Community Support
Community Support

Re: How to combine a JSON array value and loop it into a single value to email out to people

Hi @Mick282 ,

 

I have made a test on my side, please refer to screenshot below to create the flow:

1.png2.png

 

The expression in the Compose as below:

last(split(variables('test1'),'"conversation":'))

The schema in the Parse JSON as below:

{
    "type": "array",
    "items": {
        "type": "object",
        "properties": {
            "type": {
                "type": "string"
            },
            "body": {
                "type": "string"
            }
        },
        "required": [
            "type",
            "body"
        ]
    }
}

The expression in the Append to string variable as below:

concat(items('Apply_to_each')['body'],'<br><hr>')

 

The expression in the Compose 2 as below:

substring(variables('test2'),0,sub(length(variables('test2')),8))

 

The flow would run successfully as below:

4.png

 

 

Best regards,

Alice       

 

Community Support Team _ Alice Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

1 REPLY 1
Community Support
Community Support

Re: How to combine a JSON array value and loop it into a single value to email out to people

Hi @Mick282 ,

 

I have made a test on my side, please refer to screenshot below to create the flow:

1.png2.png

 

The expression in the Compose as below:

last(split(variables('test1'),'"conversation":'))

The schema in the Parse JSON as below:

{
    "type": "array",
    "items": {
        "type": "object",
        "properties": {
            "type": {
                "type": "string"
            },
            "body": {
                "type": "string"
            }
        },
        "required": [
            "type",
            "body"
        ]
    }
}

The expression in the Append to string variable as below:

concat(items('Apply_to_each')['body'],'<br><hr>')

 

The expression in the Compose 2 as below:

substring(variables('test2'),0,sub(length(variables('test2')),8))

 

The flow would run successfully as below:

4.png

 

 

Best regards,

Alice       

 

Community Support Team _ Alice Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Helpful resources

Announcements
firstImage

New Ranks and Rank Icons released on April 21!

The time has come: We are finally able to share more details on the brand-new ranks coming to the Power Automate Community!

firstImage

Now Live: Power Virtual Agents Community!

We are excited to announce the launch of Power Virtual Agents Community. Check it out now!

firstImage

New & Improved Power Automate Community Cookbook

We've updated and improved the layout and uploading format of the Power Automate Cookbook!

thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Community Summit North America

The top training and networking event across the globe for Microsoft Business Applications

Top Solution Authors
Users online (8,725)