# MQTT-IN not possible to extract only one value

**URL:** <https://discourse.nodered.org/t/mqtt-in-not-possible-to-extract-only-one-value/93931>\
**Category:** General\
**Tags:** function-node\
**Created:** [16 December 2024 10:14 UTC](https://discourse.nodered.org/t/mqtt-in-not-possible-to-extract-only-one-value/93931 "2024-12-16T10:14:28Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![autonodered](https://avatars.discourse-cdn.com/v4/letter/a/85e7bf/32.png) [@autonodered](https://discourse.nodered.org/u/autonodered)\
**Post date:** [16 December 2024 10:14 UTC](https://discourse.nodered.org/t/mqtt-in-not-possible-to-extract-only-one-value/93931/1 "2024-12-16T10:14:28Z")

</div>

hello,

I

 ![Capture d'écran 2024-12-16 110022](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/b/fb7cdc7dd325b1d4f49961b6b39a9d8a28283056.png)  
want to extract from MQTT IN only one value, it returns me 14 values ​​in the debug of which 13 are undefined, my code does not work.

Function code

```auto
var B1 = msg.payload.z.B1;
msg.payload = B1; 
return msg;

```

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [16 December 2024 10:35 UTC](https://discourse.nodered.org/t/mqtt-in-not-possible-to-extract-only-one-value/93931/2 "2024-12-16T10:35:05Z")

</div>

Use a switch node instead:

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

It will pass the message if B1 exists in payload.z  
Ofcourse it is also possible in a function node.

```auto
if("B1" in msg.payload?.z){
  return msg
}

```

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [16 December 2024 10:44 UTC](https://discourse.nodered.org/t/mqtt-in-not-possible-to-extract-only-one-value/93931/3 "2024-12-16T10:44:47Z")

</div>

As @bakman2 says, you need to test that msg.payload.z contains the key B1.  
Rather than using a function node you can easily achieve the same thing with core Node-red switch and change nodes:

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

---

<div class="post-metadata">

**Author:** ![autonodered](https://avatars.discourse-cdn.com/v4/letter/a/85e7bf/32.png) [@autonodered](https://discourse.nodered.org/u/autonodered)\
**Post date:** [16 December 2024 11:36 UTC](https://discourse.nodered.org/t/mqtt-in-not-possible-to-extract-only-one-value/93931/4 "2024-12-16T11:36:48Z")

</div>

Thanks for your help, it works.

---

<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:** [16 March 2025 11:37 UTC](https://discourse.nodered.org/t/mqtt-in-not-possible-to-extract-only-one-value/93931/5 "2025-03-16T11:37:44Z")

</div>

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