cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
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
Highlighted
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
Highlighted
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
Power Platform ISV Studio

Power Platform ISV Studio

ISV Studio is designed to become the go-to Power Platform destination for ISV’s to monitor & manage published applications.

Upcoming Events

Experience what’s next for Power Automate

See the latest Power Automate innovations, updates, and demos from the Microsoft Business Applications Launch Event.

Community Conference

Power Platform Community Conference

Find your favorite faces from the community presenting at the Power Platform Community Conference!

Top Solution Authors
Top Kudoed Authors
Users online (6,351)