# Changing message properties

**URL:** <https://discourse.nodered.org/t/changing-message-properties/1805>\
**Category:** General\
**Created:** [25 July 2018 13:20 UTC](https://discourse.nodered.org/t/changing-message-properties/1805 "2018-07-25T13:20:42Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bhoemio](https://avatars.discourse-cdn.com/v4/letter/b/b5a626/32.png) [@Bhoemio](https://discourse.nodered.org/u/Bhoemio)\
**Post date:** [25 July 2018 13:20 UTC](https://discourse.nodered.org/t/changing-message-properties/1805/1 "2018-07-25T13:20:42Z")

</div>

Hi!  
I have an **exec node** that run a python script, my python script has a while structure that sends several data once every 1 second, and the payload message that I receive isn't the same, and the payload name property is the same, so, how can I change the payload name property?  
Now I am receiving the following data:

payload: "Date: 2018/07/23 16:38:49 -- Speed: 0 kph".  
payload: "Date: 2018/07/23 16:38:49 -- Gas Level: 90%".

I want to change the first payload name to "payload.speed", and the second to "payload.gaslvl" and so on, like the following examples.

payload.speed: "Date: 2018/07/23 16:38:49 -- Speed: 0 kph".  
payload.gaslvl: "Date: 2018/07/23 16:38:49 -- Gas Level: 90%".  
payload.rpm ...

How can I solve this?

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [25 July 2018 13:50 UTC](https://discourse.nodered.org/t/changing-message-properties/1805/2 "2018-07-25T13:50:17Z")

</div>

take a look at the change node or do it in a function node after your exec node.

But most nodes expect the important data to be in msg.payload so you might find there are issues if you are attaching further nodes

---

<div class="post-metadata">

**Author:** ![Andrei](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/andrei/32/10446_2.png) [@Andrei](https://discourse.nodered.org/u/Andrei)\
**Post date:** [25 July 2018 14:14 UTC](https://discourse.nodered.org/t/changing-message-properties/1805/3 "2018-07-25T14:14:51Z")

</div>

That can be achieved with switch and change nodes. Below code will produce:

![r-01](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/e/e380c8a65d838b7eb4f1186dee1f08dd502cf83f.PNG)

Flow:

```auto
[{"id":"a2e8b28c.0ceb4","type":"tab","label":"Flow 4","disabled":false,"info":""},{"id":"b325c167.3cc55","type":"inject","z":"a2e8b28c.0ceb4","name":"speed","topic":"speed","payload":"Date: 2018/07/23 16:38:49 -- Speed: 0 kph","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":160,"wires":[["fe111fea.f6642"]]},{"id":"af3463f6.fab3f","type":"change","z":"a2e8b28c.0ceb4","name":"","rules":[{"t":"move","p":"payload","pt":"msg","to":"payload.speed","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":570,"y":160,"wires":[["53460eaf.2830d"]]},{"id":"fe111fea.f6642","type":"switch","z":"a2e8b28c.0ceb4","name":"","property":"payload","propertyType":"msg","rules":[{"t":"cont","v":"Speed","vt":"str"},{"t":"cont","v":"Gas Level","vt":"str"},{"t":"cont","v":"rpm","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":370,"y":200,"wires":[["af3463f6.fab3f"],["7cbf68a.ac0eb98"],["b4a5708a.7c78c"]]},{"id":"7cbf68a.ac0eb98","type":"change","z":"a2e8b28c.0ceb4","name":"","rules":[{"t":"move","p":"payload","pt":"msg","to":"payload.gaslvl","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":570,"y":200,"wires":[["de46d686.4c6df8"]]},{"id":"b4a5708a.7c78c","type":"change","z":"a2e8b28c.0ceb4","name":"","rules":[{"t":"move","p":"payload","pt":"msg","to":"payload.rpm","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":570,"y":240,"wires":[["eaf846cd.41b418"]]},{"id":"53460eaf.2830d","type":"debug","z":"a2e8b28c.0ceb4","name":"speed","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":790,"y":160,"wires":[]},{"id":"de46d686.4c6df8","type":"debug","z":"a2e8b28c.0ceb4","name":"gaslvl","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":790,"y":200,"wires":[]},{"id":"eaf846cd.41b418","type":"debug","z":"a2e8b28c.0ceb4","name":"rpm","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload.rpm","x":790,"y":240,"wires":[]},{"id":"166f93fd.c9e6bc","type":"inject","z":"a2e8b28c.0ceb4","name":"gaslvl","topic":"gaslvl","payload":"\"Date: 2018/07/23 16:38:49 -- Gas Level: 90%\".","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":220,"wires":[["fe111fea.f6642"]]}]

```

 ![r-02](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/b/b1be557d0eb9856da8acd7b7e59350bd39f5677d.PNG)

---

<div class="post-metadata">

**Author:** ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)\
**Post date:** [25 July 2018 15:03 UTC](https://discourse.nodered.org/t/changing-message-properties/1805/4 "2018-07-25T15:03:56Z")

</div>

Or, by moving the properties up 1 level to msg.speed, msg.gaslvl with 1 change node:

```auto
[{"id":"d605f6dc.c15438","type":"debug","z":"71dfb460.a1afbc","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":570,"y":380,"wires":[]},{"id":"9fc6ee1c.a04a2","type":"inject","z":"71dfb460.a1afbc","name":"","topic":"","payload":"Date: 2018/07/23 16:38:49 -- Speed: 0 kph","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":360,"wires":[["18435e7b.448a92"]]},{"id":"14a96805.6fb558","type":"inject","z":"71dfb460.a1afbc","name":"","topic":"","payload":"Date: 2018/07/23 16:38:49 -- Gas Level: 90%","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":400,"wires":[["18435e7b.448a92"]]},{"id":"18435e7b.448a92","type":"change","z":"71dfb460.a1afbc","name":"","rules":[{"t":"set","p":"speed","pt":"msg","to":"$contains(payload, \"Speed\") ? payload : \"\"","tot":"jsonata"},{"t":"set","p":"gaslvl","pt":"msg","to":"$contains(payload, \"Gas\") ? payload : \"\"","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":340,"y":380,"wires":[["d605f6dc.c15438"]]}]

```

![Screenshot%20at%202018-07-25%2016-00-42](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/0/0452e1f7569e6c58c2ca116bd3923ed9e5459a2c.png)

---

<div class="post-metadata">

**Author:** ![Bhoemio](https://avatars.discourse-cdn.com/v4/letter/b/b5a626/32.png) [@Bhoemio](https://discourse.nodered.org/u/Bhoemio)\
**Post date:** [26 July 2018 14:17 UTC](https://discourse.nodered.org/t/changing-message-properties/1805/6 "2018-07-26T14:17:22Z")

</div>

Thank you for your help! It solve my problem.

---

<div class="post-metadata">

**Author:** ![Bhoemio](https://avatars.discourse-cdn.com/v4/letter/b/b5a626/32.png) [@Bhoemio](https://discourse.nodered.org/u/Bhoemio)\
**Post date:** [26 July 2018 14:17 UTC](https://discourse.nodered.org/t/changing-message-properties/1805/7 "2018-07-26T14:17:28Z")

</div>

Thank you for your help!

---

<div class="post-metadata">

**Author:** ![Bhoemio](https://avatars.discourse-cdn.com/v4/letter/b/b5a626/32.png) [@Bhoemio](https://discourse.nodered.org/u/Bhoemio)\
**Post date:** [26 July 2018 14:17 UTC](https://discourse.nodered.org/t/changing-message-properties/1805/8 "2018-07-26T14:17:45Z")

</div>

Thank you for your help ghayne!

---

<div class="post-metadata">

**Author:** ![Bhoemio](https://avatars.discourse-cdn.com/v4/letter/b/b5a626/32.png) [@Bhoemio](https://discourse.nodered.org/u/Bhoemio)\
**Post date:** [26 July 2018 14:18 UTC](https://discourse.nodered.org/t/changing-message-properties/1805/9 "2018-07-26T14:18:36Z")

</div>

Thank you ukmoose for your help ^^
