web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / How to send JSON in em...
Power Automate
Suggested Answer

How to send JSON in email body with nice readable formatting?

(0) ShareShare
ReportReport
Posted on by 4
hi
 
I would like to format JSON object in emails so it is easily read.
 
The email sends out information in case an error happens and looks like that.
 
 
 
 
 
 
Is there any easy way how I can send JSON - note that the structure can change - in a nice readable format?
 
 
 
I actually created a child flow that sends out this email in case any parent flow fails. We have like 20 flows with different data structure.
 
 
 
Thank you
 
Radek
Categories:
I have the same question (0)
  • Suggested answer
    Ninjasabi Profile Picture
    122 on at

    To send a JSON object in an email with readable formatting, you can use Power Automate's HTML capabilities to structure the JSON in a way that is easy to read. Here's how you can achieve it:


    Step-by-Step Solution

    1. Convert JSON to a Readable Format

    • Use the "Compose" action to pretty-print the JSON.
    • Use the json() and string() functions:
      json(string(<Your JSON Object>))
      This ensures the JSON is formatted correctly, even if the structure changes.

    2. Format JSON with Line Breaks for Readability

    • Add the "Compose" action to insert a prettified version of the JSON object:
      • Expression to format JSON:
        replace(string(<Your JSON Object>), ',', ',<br>')
      • This adds line breaks after each key-value pair.

    3. Build the Email Body

    Use the "Send an email" action to create a well-structured email body.

    1. Subject: Add a relevant subject line.
    2. Body: Use dynamic content or the Compose output to embed the JSON.
      • Example:
        <p>An error occurred in one of the flows. Below is the JSON object:</p>
        <pre style="background-color:#f4f4f4;padding:10px;border:1px solid #ddd;border-radius:5px;">
        @{outputs('Compose')}
        </pre>

    Automating for Multiple Flows

    Since you’re using a child flow for error handling, ensure that:

    1. Pass the JSON Object to the Child Flow: Add the JSON object as an input parameter to the child flow.
    2. Dynamic Email Body in the Child Flow:
      • Use the replace expression (as shown earlier) to format the JSON dynamically.
      • Embed the formatted JSON in the email template.

    Example Output in the Email

    The JSON will appear nicely formatted and easy to read:

    {
    "Key1": "Value1",
    "Key2": "Value2",
    "Key3": {
    "SubKey1": "SubValue1",
    "SubKey2": "SubValue2"
    }
    }

    Advanced Option: HTML Table Conversion

    If you want a cleaner look, convert the JSON into an HTML table for emails:

    1. Use the "Create HTML Table" action:

      • Input: Your JSON object.
      • Output: A formatted table that you can embed directly into the email.
    2. Embed the table in the email body:

      <p>An error occurred in the flow. Below is the JSON data:</p>
      @{outputs('Create_HTML_table')}

    Final Tips

    • For unpredictable JSON structures, stick to prettified formatting with line breaks (<pre> tags work well).
    • Use a consistent design with child flows to handle multiple parent flows efficiently.

    Let me know if you’d like a detailed walkthrough of any part! 😊

  • Suggested answer
    RÅ -11121030-0 Profile Picture
    4 on at
    @Ninjasabi
    {
    "Key1": "Value1",
    "Key2": "Value2",
    "Key3": {
      "SubKey1": "SubValue1",
      "SubKey2": "SubValue2"
      }
    }
     
     
    could I have it formatted - see above - instead of
    {
    "Key1": "Value1",
    "Key2": "Value2",
    "Key3": {
    "SubKey1": "SubValue1",
    "SubKey2": "SubValue2"
    }
    }
    this way? So the nesting is more "visible"?
     
    Thank you
    Radek

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 503 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 321 Moderator

#3
abm abm Profile Picture

abm abm 237 Most Valuable Professional

Last 30 days Overall leaderboard