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

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
v-alzhan-msft
Community Support
Community Support

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
v-alzhan-msft
Community Support
Community Support

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
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Top Solution Authors
Users online (1,263)