# Pick just one value from a MQTT message

**URL:** <https://discourse.nodered.org/t/pick-just-one-value-from-a-mqtt-message/18998>\
**Category:** General\
**Created:** [10 December 2019 14:32 UTC](https://discourse.nodered.org/t/pick-just-one-value-from-a-mqtt-message/18998 "2019-12-10T14:32:25Z")\
**Posts on this page:** 6\
**Page:** 2

<div class="post-metadata">

**Author:** ![GravityRZ](https://avatars.discourse-cdn.com/v4/letter/g/839c29/32.png) [@GravityRZ](https://discourse.nodered.org/u/GravityRZ)\
**Post date:** [15 December 2019 17:06 UTC](https://discourse.nodered.org/t/pick-just-one-value-from-a-mqtt-message/18998/21 "2019-12-15T17:06:28Z")

</div>

maybee you got this already figured out but the quesyion seemed simple.

you do not need change nodes, just a function

{"id":"405c9277.fcf69c","type":"inject","z":"ff5d1e85.d8ebe","name":"","topic":"","payload":"{"Time":"2019-12-10T15:30:16","TSL2561":{"Illuminance":56.190}}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":370,"y":240,"wires":[["85d55443.88abc8"]]},{"id":"e40ed4b6.3a00c8","type":"debug","z":"ff5d1e85.d8ebe","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":730,"y":240,"wires":},{"id":"85d55443.88abc8","type":"function","z":"ff5d1e85.d8ebe","name":"","func":"var Illuminance = msg.payload.TSL2561.Illuminance\nmsg.payload = Illuminance\nreturn msg;","outputs":1,"noerr":0,"x":510,"y":240,"wires":[["e40ed4b6.3a00c8"]]}

---

<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:** [16 December 2019 21:34 UTC](https://discourse.nodered.org/t/pick-just-one-value-from-a-mqtt-message/18998/22 "2019-12-16T21:34:45Z")

</div>

> [@GravityRZ](#):
>
> you do not need change nodes, just a function

Or, you do not need a `function` node, if you can use a `change` node...  
Why write code if you don't have to?

---

<div class="post-metadata">

**Author:** ![drmibell](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/drmibell/32/8424_2.png) [@drmibell](https://discourse.nodered.org/u/drmibell)\
**Post date:** [16 December 2019 21:54 UTC](https://discourse.nodered.org/t/pick-just-one-value-from-a-mqtt-message/18998/23 "2019-12-16T21:54:40Z")

</div>

> [@shrickus](#):
>
> Why write code if you don't have to?

Because sometimes the difference between a `function` node and a `change` node is the difference between writing JavaScript and writing JSONata 🙂

---

<div class="post-metadata">

**Author:** ![GravityRZ](https://avatars.discourse-cdn.com/v4/letter/g/839c29/32.png) [@GravityRZ](https://discourse.nodered.org/u/GravityRZ)\
**Post date:** [17 December 2019 07:57 UTC](https://discourse.nodered.org/t/pick-just-one-value-from-a-mqtt-message/18998/24 "2019-12-17T07:57:00Z")

</div>

agreed if the choice is between function node versus change node  
most of the times you still need something more and you can do that in a function node instead of creating another node.

e.g. in this example we were talking about one variable.  
what if you had 100, you can still do it with one function node, give it multiple outputs.

second example: function nodes can work with variables while change nodes can not

eg. in a change node set variable to flow.device.{{variable}}

the idea of Node-red is to keep things simple so creating lot's of nodes is not the way to go but creating 1 function node which can do it all neither

i am still a beginner when it comes to node-red but figured out a lot of smart functionality, just by trying out things in the code(it is Javascript and you can find a lot on google)

---

<div class="post-metadata">

**Author:** ![Quart666](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/quart666/32/12072_2.png) [@Quart666](https://discourse.nodered.org/u/Quart666)\
**Post date:** [17 December 2019 08:21 UTC](https://discourse.nodered.org/t/pick-just-one-value-from-a-mqtt-message/18998/25 "2019-12-17T08:21:58Z")

</div>

Tried to import that code, didnt work. Not a json array...

---

<div class="post-metadata">

**Author:** ![GravityRZ](https://avatars.discourse-cdn.com/v4/letter/g/839c29/32.png) [@GravityRZ](https://discourse.nodered.org/u/GravityRZ)\
**Post date:** [17 December 2019 08:40 UTC](https://discourse.nodered.org/t/pick-just-one-value-from-a-mqtt-message/18998/26 "2019-12-17T08:40:18Z")

</div>

[{"id":"405c9277.fcf69c","type":"inject","z":"ff5d1e85.d8ebe","name":"","topic":"","payload":"{"Time":"2019-12-10T15:30:16","TSL2561":{"Illuminance":56.190}}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":370,"y":240,"wires":[["85d55443.88abc8"]]},{"id":"e40ed4b6.3a00c8","type":"debug","z":"ff5d1e85.d8ebe","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":730,"y":240,"wires":},{"id":"85d55443.88abc8","type":"function","z":"ff5d1e85.d8ebe","name":"","func":"var Illuminance = msg.payload.TSL2561.Illuminance\nmsg.payload = Illuminance\nreturn msg;","outputs":1,"noerr":0,"x":510,"y":240,"wires":[["e40ed4b6.3a00c8"]]}]

to give you an idea how to get variables from json strings

[Previous page](https://discourse.nodered.org/t/pick-just-one-value-from-a-mqtt-message/18998.md?page=1)
