# Change a mqtt message property

**URL:** https://discourse.nodered.org/t/change-a-mqtt-message-property/56476
**Category:** General
**Created:** [11 January 2022 15:50 UTC](https://discourse.nodered.org/t/change-a-mqtt-message-property/56476 "2022-01-11T15:50:49Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![gjones84](https://avatars.discourse-cdn.com/v4/letter/g/7cd45c/32.png) [@gjones84](https://discourse.nodered.org/u/gjones84)
#### Post date: [11 January 2022 15:50 UTC](https://discourse.nodered.org/t/change-a-mqtt-message-property/56476/1 "2022-01-11T15:50:49Z")

</div>

Hi All,

Hopefully a really easy one for someone. Im still a newbe to node red. If I have a mqtt message coming into a flow of a value -200. In the debug window it looks like this.

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

How do I change the message properties is so that it looks like this below.

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/4/b435a3af90d8660847c0194c0f88c80b393a3083.png)

This what I have composed so far.

```auto
[{"id":"ecfdacce.ba719","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"d11f7e94.99f4","type":"inject","z":"ecfdacce.ba719","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"-200","payloadType":"num","x":530,"y":280,"wires":[["5710bad6.8ddbd4","3672fb61.c48564"]]},{"id":"5710bad6.8ddbd4","type":"debug","z":"ecfdacce.ba719","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":930,"y":280,"wires":[]},{"id":"3672fb61.c48564","type":"change","z":"ecfdacce.ba719","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"value","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":720,"y":440,"wires":[["5710bad6.8ddbd4"]]}]

```

Any help would be much appreciated.

Cheers

Gareth

---

<div class="post-metadata">

### Author: ![mickym2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mickym2/32/36128_2.png) [@mickym2](https://discourse.nodered.org/u/mickym2)
#### Post date: [11 January 2022 15:54 UTC](https://discourse.nodered.org/t/change-a-mqtt-message-property/56476/2 "2022-01-11T15:54:15Z")

</div>

Take a change node and move payload to payload.value.

---

<div class="post-metadata">

### Author: ![gjones84](https://avatars.discourse-cdn.com/v4/letter/g/7cd45c/32.png) [@gjones84](https://discourse.nodered.org/u/gjones84)
#### Post date: [12 January 2022 08:32 UTC](https://discourse.nodered.org/t/change-a-mqtt-message-property/56476/3 "2022-01-12T08:32:52Z")

</div>

@mickym2 thanks for your reply. Pretty much there.

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/4/44ad618679fc148e6f05af44dc506eb0dccac46e.png)

how do I now get the quotation marks either side of the value?

cheers

---

<div class="post-metadata">

### Author: ![hardillb](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hardillb/32/12373_2.png) [@hardillb](https://discourse.nodered.org/u/hardillb)
#### Post date: [12 January 2022 08:41 UTC](https://discourse.nodered.org/t/change-a-mqtt-message-property/56476/4 "2022-01-12T08:41:56Z")

</div>

That depends on what you actually want.

If you need the output to be a JSON Object then you don't need to do anything, it's just how the sidebar displays objects. (you can see what you are showing is an object because it says `object` next to `msg.payload`

If what you need is a JSON Object encoded as a String (where the quotes are required for it to be valid) then you need to pass the output of the change node through a JSON node (this will convert Object to string or vice versa based on the input).

---

<div class="post-metadata">

### Author: ![grant1](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/grant1/32/49890_2.png) [@grant1](https://discourse.nodered.org/u/grant1)
#### Post date: [12 January 2022 10:50 UTC](https://discourse.nodered.org/t/change-a-mqtt-message-property/56476/5 "2022-01-12T10:50:33Z")

</div>

Also, what is the output set to on your MQTT node?

---

<div class="post-metadata">

### Author: ![gjones84](https://avatars.discourse-cdn.com/v4/letter/g/7cd45c/32.png) [@gjones84](https://discourse.nodered.org/u/gjones84)
#### Post date: [12 January 2022 13:13 UTC](https://discourse.nodered.org/t/change-a-mqtt-message-property/56476/6 "2022-01-12T13:13:22Z")

</div>

@hardillb and @grant. Long story short I was trying to publish a calculated value to a mqtt broker.

Just tried sending { value: -200} and the piece of equipment is now responding. Before I sent just -200 and it did nothing.

**Also, what is the output set to on your MQTT node?**  
I know on a 'mqtt in' node you can set the message output to a parsed json object/buffer/string. This cant be done via a 'mqtt out' node. Maybe a something that should be added in the future?

thanks for your help 🙂

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [12 January 2022 13:21 UTC](https://discourse.nodered.org/t/change-a-mqtt-message-property/56476/7 "2022-01-12T13:21:05Z")

</div>

> [@gjones84](#):
>
> I know on a 'mqtt in' node you can set the message output to a parsed json object/buffer/string. This cant be done via a 'mqtt out' node

MQTT essentially transmits strings only. So behind the scenes (to assist you) the MQTT out node does it's best to assist you. It's only the MQTT in node where you need be concerned.

A better solution is to use the features of MQTT v5 & provide a content type in the transmission. Then perhaps "auto" mode (or a new v5 auto mode) could do a more informed job of figuring out what the MQTT payload was intended to be. Something I have in the back of my minds "to do" list.

---

<div class="post-metadata">

### Author: ![mickym2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mickym2/32/36128_2.png) [@mickym2](https://discourse.nodered.org/u/mickym2)
#### Post date: [12 January 2022 13:31 UTC](https://discourse.nodered.org/t/change-a-mqtt-message-property/56476/8 "2022-01-12T13:31:02Z")

</div>

Just send the payload to a JSON Node - and the JS Object will be changed into a string, a JSON string

---

<div class="post-metadata">

### Author: ![hardillb](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hardillb/32/12373_2.png) [@hardillb](https://discourse.nodered.org/u/hardillb)
#### Post date: [12 January 2022 13:46 UTC](https://discourse.nodered.org/t/change-a-mqtt-message-property/56476/9 "2022-01-12T13:46:01Z")

</div>

Bytes only, if they just happen to be UTF-8 characters then so be it.

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [12 January 2022 13:55 UTC](https://discourse.nodered.org/t/change-a-mqtt-message-property/56476/10 "2022-01-12T13:55:01Z")

</div>

> [@hardillb](#):
>
> Bytes only, if they just happen to be UTF-8 characters

Yeah, was an attempt to simplify for readers

My real point was using v5 & content type, we could be more intelligent in the auto conversion.

Something I have mulled over since adding v5 support to the MQTT nodes - a missed opportunity I feel?

---

<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: [26 January 2022 13:55 UTC](https://discourse.nodered.org/t/change-a-mqtt-message-property/56476/11 "2022-01-26T13:55:31Z")

</div>

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