# Extract value from MQTT message

**URL:** <https://discourse.nodered.org/t/extract-value-from-mqtt-message/72714>\
**Category:** General\
**Created:** [26 December 2022 10:09 UTC](https://discourse.nodered.org/t/extract-value-from-mqtt-message/72714 "2022-12-26T10:09:02Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![HaVi](https://avatars.discourse-cdn.com/v4/letter/h/b3f665/32.png) [@HaVi](https://discourse.nodered.org/u/HaVi)\
**Post date:** [26 December 2022 10:09 UTC](https://discourse.nodered.org/t/extract-value-from-mqtt-message/72714/1 "2022-12-26T10:09:02Z")

</div>

I need some help extracting one value (as float or integer) from an MQTT message. This is the relevant part of the MQTT message:

```auto
{"BatV":3.041,"Bat_status":3,"Exti_pin_level":"Low","Exti_status":"False","Hum_SHT":71.6,"No_connect":"Sensor no connection","TempC_SHT":13.86 ,"Work_mode":"Interrupt Sensor send"}

```

Only the value "TempC\_SHT" is needed and I think I should use the change node but unfortunately I can't. Can someone tell me how to set up the node?

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [26 December 2022 10:19 UTC](https://discourse.nodered.org/t/extract-value-from-mqtt-message/72714/2 "2022-12-26T10:19:04Z")

</div>

What is the output of the mqtt node is it a string or object, what settings did you set output to in the mqtt node.

If it is an object  
the value would be at `msg.payload.TempC_SHT`  
you can use as is or if you want to move it to msg.payload then  
set the change node to  
set `msg.` `payload`  
to `msg.` `payload.TempC_SHT`

---

<div class="post-metadata">

**Author:** ![HaVi](https://avatars.discourse-cdn.com/v4/letter/h/b3f665/32.png) [@HaVi](https://discourse.nodered.org/u/HaVi)\
**Post date:** [26 December 2022 11:07 UTC](https://discourse.nodered.org/t/extract-value-from-mqtt-message/72714/3 "2022-12-26T11:07:29Z")

</div>

Thanks for helping!

Not sure if it is a string, this is the debug info I receive winthin NR so it looks like an object:

![payload](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/4/541f71099d5ceb32f45b2c25be7cb4b36b6a433c.png)

Is this helpfull? My first try to set the change node resulted in "undefined".

---

<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:** [26 December 2022 11:15 UTC](https://discourse.nodered.org/t/extract-value-from-mqtt-message/72714/4 "2022-12-26T11:15:11Z")

</div>

There’s a great page in the docs ([Working with messages : Node-RED](https://nodered.org/docs/user-guide/messages)) that will explain how to use the debug panel to find the right path to any data item.

Pay particular attention to the part about the buttons that appear under your mouse pointer when you over hover a debug message property in the sidebar.

![BX00Cy7yHi](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/d/bd1f333a9e043b061b39917c328b0094d3e52d30.gif)

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [26 December 2022 11:30 UTC](https://discourse.nodered.org/t/extract-value-from-mqtt-message/72714/5 "2022-12-26T11:30:53Z")

</div>

From your image the object is in `decoded_payload` not `payload`. That may be in another property also, but your image does not show enough info to know for sure. Normally the mqtt node outputs on payload, so you must have other nodes in between it and the debug that have moved the payload.

Use @zenofmud post to get the exact property path.

---

<div class="post-metadata">

**Author:** ![HaVi](https://avatars.discourse-cdn.com/v4/letter/h/b3f665/32.png) [@HaVi](https://discourse.nodered.org/u/HaVi)\
**Post date:** [26 December 2022 12:25 UTC](https://discourse.nodered.org/t/extract-value-from-mqtt-message/72714/6 "2022-12-26T12:25:55Z")

</div>

With your help it was solved, thanks E1cid and zenofmud!

 ![Solved](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/6/f6c7a63777e90f3667fb9a864bb62878bc9a27e0.png)

---

<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:** [9 January 2023 12:26 UTC](https://discourse.nodered.org/t/extract-value-from-mqtt-message/72714/7 "2023-01-09T12:26:24Z")

</div>

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