# How to format JSON output in table to send in the body of the email

**URL:** https://discourse.nodered.org/t/how-to-format-json-output-in-table-to-send-in-the-body-of-the-email/96661
**Category:** General
**Created:** [20 April 2025 21:27 UTC](https://discourse.nodered.org/t/how-to-format-json-output-in-table-to-send-in-the-body-of-the-email/96661 "2025-04-20T21:27:00Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![VaraVerde-hub](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/varaverde-hub/32/100250_2.png) [@VaraVerde-hub](https://discourse.nodered.org/u/VaraVerde-hub)
#### Post date: [20 April 2025 21:27 UTC](https://discourse.nodered.org/t/how-to-format-json-output-in-table-to-send-in-the-body-of-the-email/96661/1 "2025-04-20T21:27:00Z")

</div>

Hi guys.

I need help to form a JSON output, I need to format it in a table for the body of the email that will be sent. Can anyone help me with any tips?

Thank you for your attention.

this is my test flow:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/6/a6dd7880f368085541c83731b4d2542595167b88.png)

How is the body of the email:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/8/98ae7216e976bc3571c9c68d02c3808379850a62.png)

---

<div class="post-metadata">

### Author: ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)
#### Post date: [20 April 2025 22:44 UTC](https://discourse.nodered.org/t/how-to-format-json-output-in-table-to-send-in-the-body-of-the-email/96661/2 "2025-04-20T22:44:11Z")

</div>

You can use a template node and use mustache syntax to generate the html  
or javascript in a Function node to loop through the data array with the same result.

Here is small example flow with JS

```auto
[{"id":"0d20057e4d5ebf5d","type":"inject","z":"54efb553244c241f","name":"data","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[{\"sales_month\":\"1992-01-01T00:00:00.000Z\",\"naics_code\":\"441\",\"kind_of_business\":\"Motor vehicle and parts dealers\",\"reason_for_null\":\"\",\"sales\":29811},{\"sales_month\":\"1992-01-01T00:00:00.000Z\",\"naics_code\":\"4411\",\"kind_of_business\":\"Automobile dealers\",\"reason_for_null\":\"\",\"sales\":25800}]","payloadType":"json","x":250,"y":3820,"wires":[["209cb742129d44fb"]]},{"id":"209cb742129d44fb","type":"function","z":"54efb553244c241f","name":"table","func":"// \"sales_month\": \"1992-01-01T00:00:00.000Z\",\n// \"naics_code\": \"4411\",\n// \"kind_of_business\": \"Automobile dealers\",\n// \"reason_for_null\": \"\",\n// \"sales\": 25800\n\nlet tableHtml = `<table>\n <tr>\n <td>Sales Month</td>\n <td>Naics Code</td>\n <td>Kind of business</td>\n <td>Reason for null</td>\n <td>Sales</td>\n </tr>\n ` \nmsg.payload.forEach(el => {\n tableHtml += `<tr>\n <td>${el.sales_month}</td>\n <td>${el.naics_code}</td>\n <td>${el.kind_of_business}</td>\n <td>${el.reason_for_null}</td>\n <td>${el.sales}</td>\n </tr>`\n })\n\ntableHtml += `</table>`\n\nmsg.payload = tableHtml\n\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":410,"y":3820,"wires":[["608246100beee2a2"]]},{"id":"608246100beee2a2","type":"debug","z":"54efb553244c241f","name":"debug 23","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":610,"y":3820,"wires":[]}]

```

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/0/d0f16ce575e2c932ef313f15ea8b9ed7e6b1b339.png)

You will need some styling and alignment to make it more presentable.

---

<div class="post-metadata">

### Author: ![VaraVerde-hub](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/varaverde-hub/32/100250_2.png) [@VaraVerde-hub](https://discourse.nodered.org/u/VaraVerde-hub)
#### Post date: [20 April 2025 23:04 UTC](https://discourse.nodered.org/t/how-to-format-json-output-in-table-to-send-in-the-body-of-the-email/96661/3 "2025-04-20T23:04:57Z")

</div>

Thanks so much for the example, it was super helpful! 👏

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [21 April 2025 01:16 UTC](https://discourse.nodered.org/t/how-to-format-json-output-in-table-to-send-in-the-body-of-the-email/96661/4 "2025-04-21T01:16:30Z")

</div>

You could also use uibuilde's uib-element and uib-html to generate an html table from source data.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [5 May 2025 01:17 UTC](https://discourse.nodered.org/t/how-to-format-json-output-in-table-to-send-in-the-body-of-the-email/96661/5 "2025-05-05T01:17:00Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
