# How to add a prefix to msg.payload

**URL:** https://discourse.nodered.org/t/how-to-add-a-prefix-to-msg-payload/7899
**Category:** General
**Created:** [12 February 2019 20:36 UTC](https://discourse.nodered.org/t/how-to-add-a-prefix-to-msg-payload/7899 "2019-02-12T20:36:01Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Giaitzoglou](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/giaitzoglou/32/5947_2.png) [@Giaitzoglou](https://discourse.nodered.org/u/Giaitzoglou)
#### Post date: [12 February 2019 20:36 UTC](https://discourse.nodered.org/t/how-to-add-a-prefix-to-msg-payload/7899/1 "2019-02-12T20:36:01Z")

</div>

hi i know its going to be something simple what i what is to help me with:

i want to convert the number 1-255 that comes from a dashboard slider to 0:number for exmle 0:255 and then send it via mqtt ?  
how is that possible ?  
thanks in advance  
chris giaitzoglou

---

<div class="post-metadata">

### Author: ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)
#### Post date: [12 February 2019 20:48 UTC](https://discourse.nodered.org/t/how-to-add-a-prefix-to-msg-payload/7899/2 "2019-02-12T20:48:37Z")

</div>

You could use a change node with a jsonata expression  
or a change node with a cuple rules to set x = '0:qaz then replace qaz with msg.payload then move x to msg.payload  
or a function node

what have you attemped so far?

---

<div class="post-metadata">

### Author: ![Giaitzoglou](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/giaitzoglou/32/5947_2.png) [@Giaitzoglou](https://discourse.nodered.org/u/Giaitzoglou)
#### Post date: [13 February 2019 00:41 UTC](https://discourse.nodered.org/t/how-to-add-a-prefix-to-msg-payload/7899/3 "2019-02-13T00:41:33Z")

</div>

> [@zenofmud](#):
>
> 0:qaz

wow i never would have through to use a change node like this ever! but it makes really sense the logic thanks for that you help a lot also to think differently .  
As you may have guess i am newbie i also just starting to learn java script , itried a function node where i had something like this  
var msg=msg.payload  
var newMsg= 0;  
var newMsg1=":"  
return [newMsg,newMsg1,msg]  
but it diidnt work (in my head the logic was good but it got me to an error)  
thanks again for your help

---

<div class="post-metadata">

### Author: ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)
#### Post date: [13 February 2019 02:47 UTC](https://discourse.nodered.org/t/how-to-add-a-prefix-to-msg-payload/7899/4 "2019-02-13T02:47:32Z")

</div>

Try a change node with a jaonata item and a value of “0:”&payload

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [13 February 2019 08:33 UTC](https://discourse.nodered.org/t/how-to-add-a-prefix-to-msg-payload/7899/5 "2019-02-13T08:33:03Z")

</div>

If you want to use a function then it would be something like

```auto
msg.payload = "0:" + msg.payload;
return msg;

```

or if you are using a current version of node.js then you can use the new string interpolation syntax which is neater

```auto
msg.payload = `0:${msg.payload}`;
return msg;

```

---

<div class="post-metadata">

### Author: ![shrickus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shrickus/32/517_2.png) [@shrickus](https://discourse.nodered.org/u/shrickus)
#### Post date: [14 February 2019 05:33 UTC](https://discourse.nodered.org/t/how-to-add-a-prefix-to-msg-payload/7899/6 "2019-02-14T05:33:48Z")

</div>

There are probably a dozen ways to concatenate your incoming payload with another string -- besides those already suggested, I think the simplest is the `template` node. You can use the following "mustache" syntax to get the output you want:

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/6/658219c1de16164981a55790f46d91a93dcb0ea6.png)

Note that the `msg.` prefix is not used inside the variable substitution braces, e.g. `{{ payload }}`, since all the named fields are expected to come from the incoming `msg` object.
