cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Mick282
Level: Powered On

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 Team
Community Support Team

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 Team
Community Support Team

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

Incoming: New and improved badges!

Look out for new contribution recognition badges coming SOON!

firstImage

Power Platform Online Conference

Join us for the first ever Power Platform Online Conference!

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!

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

sixthImage

Power Platform World Tour

Find out where you can attend!

seventhimage

Webinars & Video Gallery

Watch & learn from the Power Automate Community Video Gallery!

Top Solution Authors
Top Kudoed Authors
Users online (5,686)