Home > Back-end >  How to turn a json string into a properly beautified string to be used in email using a Logic App
How to turn a json string into a properly beautified string to be used in email using a Logic App

Time:02-05

Logic App

enter image description here

enter image description here

"Send_an_email_(V2)": {
                "inputs": {
                    "body": {
                        "Body": "<p><br></p>\n<pre><code>Message 1<br>\n<br>\n@{variables('Message1')}<br>\n<br>\nMessage 2<br>\n<br>\n@{variables('Message2')}</code></pre>\n<pre><code><br>\n<br>\n<br>\n<br>\n</code></pre>",
                        "Importance": "Normal",
                        "Subject": "Test",
                        "To": "[email protected]"
                    }

This is how it looks like in the email. I know the Message 2 has it already nicely formatted but I would want both to look the same.

Any ideas are appreciated.

enter image description here

CodePudding user response:

After reproducing issue from my side, I got the expected results by taking Parse Json Action after initialize variable action.
As shown in below images i have taken initialize variable actions and send email.
enter image description here

enter image description here

enter image description here

enter image description here

With out parse Json action I got below output in email.
enter image description here

As shown in below image in Parse Json action take Content as Message 1 from dynamic content .
Schema :

{
  "Request_Date": "2023-07-18",
  "Number_of_Adults": "5",
  "Number_of_Children": "1",
  "Total_Cost": "690"
}

enter image description here

Then in Send Email action in body take your required data from dynamic content of parse Json 1 as shown in below image.
enter image description here

Then the logic App ran successfully and email got received with expected output format.
enter image description here

enter image description here

Reference enter image description here

replace(replace(replace(variables('Message1'),',',',<br>&nbsp;&nbsp;&nbsp;&nbsp;'),'{','{<br>&nbsp;&nbsp;&nbsp;&nbsp;'),'}','<br>}')
  • Related