# \[solved\] Concate msg.payload to array value in template

**URL:** <https://discourse.nodered.org/t/solved-concate-msg-payload-to-array-value-in-template/70303>\
**Category:** General\
**Created:** [9 November 2022 06:51 UTC](https://discourse.nodered.org/t/solved-concate-msg-payload-to-array-value-in-template/70303 "2022-11-09T06:51:15Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![digidax](https://avatars.discourse-cdn.com/v4/letter/d/edb3f5/32.png) [@digidax](https://discourse.nodered.org/u/digidax)\
**Post date:** [9 November 2022 06:51 UTC](https://discourse.nodered.org/t/solved-concate-msg-payload-to-array-value-in-template/70303/1 "2022-11-09T06:51:16Z")

</div>

Hi there,  
I'm using a template for preparing a msg to send it with simple sendmail.

How can I append the value with the msg.payload? (text line for email message)?  
**"text": "Device: "+ msg.payload** is syntactically incorrect.

```auto
{
    "transport": {
        "host": "localhost",
        "port": 587,
        "auth": {
            "user": "foo", 
            "pass": "000"
        }
    },
    "options": {
        "from": "test@dom.com",
        "to": "user@test",
        "subject": "WARNING",
        "text": "Device: "+ msg.payload
    }
}

```

trying "text": "Device: {{msg.payload}}" brings no payload value into the string.

Thanks for helping.  
Frank

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [9 November 2022 08:28 UTC](https://discourse.nodered.org/t/solved-concate-msg-payload-to-array-value-in-template/70303/2 "2022-11-09T08:28:32Z")

</div>

Try

```auto
{
    "transport": {
        "host": "localhost",
        "port": 587,
        "auth": {
            "user": "foo", 
            "pass": "000"
        }
    },
    "options": {
        "from": "test@dom.com",
        "to": "user@test",
        "subject": "WARNING",
        "text": "Device: {{payload}}"
    }
}

```

---

<div class="post-metadata">

**Author:** ![digidax](https://avatars.discourse-cdn.com/v4/letter/d/edb3f5/32.png) [@digidax](https://discourse.nodered.org/u/digidax)\
**Post date:** [9 November 2022 09:30 UTC](https://discourse.nodered.org/t/solved-concate-msg-payload-to-array-value-in-template/70303/3 "2022-11-09T09:30:05Z")

</div>

> [@E1cid](#):
>
> ` {{payload}}`

Thanks, but get the error: "Unexpected token in JSON at position 366"

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [9 November 2022 09:32 UTC](https://discourse.nodered.org/t/solved-concate-msg-payload-to-array-value-in-template/70303/4 "2022-11-09T09:32:31Z")

</div>

Please post your flow as you said template, i assumed template node. I see from your reply this may not be the case.

If this is a HA node try JSONata J:

```auto
{
    "transport": {
        "host": "localhost",
        "port": 587,
        "auth": {
            "user": "foo", 
            "pass": "000"
        }
    },
    "options": {
        "from": "test@dom.com",
        "to": "user@test",
        "subject": "WARNING",
        "text": "Device: " & $$.payload
    }
}

```

---

<div class="post-metadata">

**Author:** ![digidax](https://avatars.discourse-cdn.com/v4/letter/d/edb3f5/32.png) [@digidax](https://discourse.nodered.org/u/digidax)\
**Post date:** [9 November 2022 10:02 UTC](https://discourse.nodered.org/t/solved-concate-msg-payload-to-array-value-in-template/70303/5 "2022-11-09T10:02:13Z")

</div>

After error and try: GOT IT. Your first answer was the right direction but not:

```auto
{{payload}}

```

The are to add white spaces before and after "payload":

```auto
{{ payload }}

```

now its worling well. Thanks.

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [9 November 2022 10:07 UTC](https://discourse.nodered.org/t/solved-concate-msg-payload-to-array-value-in-template/70303/6 "2022-11-09T10:07:21Z")

</div>

You are mistaken, the white space makes no difference  
eg

```auto
[{"id":"1c0bb849507f28ad","type":"inject","z":"452103ea51141731","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"test","payloadType":"str","x":170,"y":3260,"wires":[["7ea7f6fecad53836","273f04f42cd37a26"]]},{"id":"7ea7f6fecad53836","type":"template","z":"452103ea51141731","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{\n \"transport\": {\n \"host\": \"localhost\",\n \"port\": 587,\n \"auth\": {\n \"user\": \"foo\", \n \"pass\": \"000\"\n }\n },\n \"options\": {\n \"from\": \"test@dom.com\",\n \"to\": \"user@test\",\n \"subject\": \"WARNING\",\n \"text\": \"Device: {{payload}}\"\n }\n}","output":"str","x":320,"y":3260,"wires":[["543d77c6f929e577"]]},{"id":"273f04f42cd37a26","type":"template","z":"452103ea51141731","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{\n \"transport\": {\n \"host\": \"localhost\",\n \"port\": 587,\n \"auth\": {\n \"user\": \"foo\", \n \"pass\": \"000\"\n }\n },\n \"options\": {\n \"from\": \"test@dom.com\",\n \"to\": \"user@test\",\n \"subject\": \"WARNING\",\n \"text\": \"Device: {{ payload }}\"\n }\n}","output":"str","x":320,"y":3300,"wires":[["1cd8e2bd56d0b608"]]},{"id":"543d77c6f929e577","type":"debug","z":"452103ea51141731","name":"debug 106","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":510,"y":3240,"wires":[]},{"id":"1cd8e2bd56d0b608","type":"debug","z":"452103ea51141731","name":"debug 107","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":510,"y":3300,"wires":[]}]

```

You can see both formats work in image below

 ![chrome_screenshot_1667988332740](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/4/044a6199c363eb2f84b37c5c2980da743bf28632.png)  
Also if you are using aJSON node, it is not required as template node can output an object.  
e.g.

```auto
[{"id":"1c0bb849507f28ad","type":"inject","z":"452103ea51141731","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"test","payloadType":"str","x":170,"y":3260,"wires":[["7ea7f6fecad53836"]]},{"id":"7ea7f6fecad53836","type":"template","z":"452103ea51141731","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{\n \"transport\": {\n \"host\": \"localhost\",\n \"port\": 587,\n \"auth\": {\n \"user\": \"foo\", \n \"pass\": \"000\"\n }\n },\n \"options\": {\n \"from\": \"test@dom.com\",\n \"to\": \"user@test\",\n \"subject\": \"WARNING\",\n \"text\": \"Device: {{payload}}\"\n }\n}","output":"json","x":320,"y":3260,"wires":[["543d77c6f929e577"]]},{"id":"543d77c6f929e577","type":"debug","z":"452103ea51141731","name":"debug 106","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":510,"y":3240,"wires":[]}]

```

 ![chrome_screenshot_1667988975200](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/b/eb9dd87c8bf3f4d69f0a75e9f3048e0e4902a8ea.png)

---

<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:** [8 January 2023 10:07 UTC](https://discourse.nodered.org/t/solved-concate-msg-payload-to-array-value-in-template/70303/7 "2023-01-08T10:07:23Z")

</div>

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