# How to extract temperature from msg.payload

**URL:** <https://discourse.nodered.org/t/how-to-extract-temperature-from-msg-payload/100583>\
**Category:** General\
**Tags:** function-node\
**Created:** [17 March 2026 16:18 UTC](https://discourse.nodered.org/t/how-to-extract-temperature-from-msg-payload/100583 "2026-03-17T16:18:49Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![satkey3](https://avatars.discourse-cdn.com/v4/letter/s/cc9497/32.png) [@satkey3](https://discourse.nodered.org/u/satkey3)\
**Post date:** [17 March 2026 16:18 UTC](https://discourse.nodered.org/t/how-to-extract-temperature-from-msg-payload/100583/1 "2026-03-17T16:18:49Z")

</div>

Hi,  
I want to extract temperature from this msg.payload , using buffer parsing node or function node:

msg.payload : string[151]  
"{"endpoint":{"serial\_number":"4cea591f-cb62-47b8-8eac-e3bddee155c6","third\_serial\_number":"10024d01f3"},"payload":{"temperature":{"temperature":67.4}}}"

Thank you

---

<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:** [17 March 2026 16:24 UTC](https://discourse.nodered.org/t/how-to-extract-temperature-from-msg-payload/100583/2 "2026-03-17T16:24:27Z")

</div>

Why do you need to extract it (where are you sending it)?

If the value is an object then you can simply use its path `msg.this.that` in the next node or you can use a change node to set `msg.payload` to the value of `msg.this.that`

Here is some canned text that should help you understand.

* * *

## Getting path to any property in the msg

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/value for 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)

* * *

## more tips and tricks

I recommend watching this playlist: [Node-RED Essentials](https://www.youtube.com/playlist?list=PLyNBB9VCLmo1hyO-4fIZ08gqFcXBkHy-6). The videos are done by the developers of node-red. They're nice & short and to the point. You will understand a whole lot more in about 1 hour. A small investment for a lot of gain.

---

<div class="post-metadata">

**Author:** ![satkey3](https://avatars.discourse-cdn.com/v4/letter/s/cc9497/32.png) [@satkey3](https://discourse.nodered.org/u/satkey3)\
**Post date:** [17 March 2026 16:38 UTC](https://discourse.nodered.org/t/how-to-extract-temperature-from-msg-payload/100583/3 "2026-03-17T16:38:07Z")

</div>

I want to send the temperature result to a function:

const temperature = msg.payload.temperature  
let result = 0  
if(temperature \> 70) {result=1}  
if(temperature \<= 70) {result=2}  
msg.payload = result  
return msg;

And this result will send to a swich function to open or close some automatizations in my house

---

<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:** [17 March 2026 16:47 UTC](https://discourse.nodered.org/t/how-to-extract-temperature-from-msg-payload/100583/4 "2026-03-17T16:47:04Z")

</div>

> [@satkey3](#):
>
> I want to send the temperature result to a function:

ok, so wire whatever node creates the message with temperature to the function and use it.

If you send the output to a debug node you can get the exact path to the property as I showed in the tip.

EDIT: I have just noticed your msg.payload is a string not an object. So, pass the msg through a JSON node first and it will be converted to an object where you can use the tip I mentioned before ↓ this tip ↓

> [@Steve-Mcl](#):
>
> 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)

its a nifty helper to help you do exactly this kinda thing.

* * *

PS, please consider watching the videos - they are a ton of help for folk new or inexperienced in Node-RED.

---

<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:** [17 March 2026 16:48 UTC](https://discourse.nodered.org/t/how-to-extract-temperature-from-msg-payload/100583/5 "2026-03-17T16:48:35Z")

</div>

> [@Steve-Mcl](#):
>
> EDIT: I have just noticed your msg.payload is a string not an object. So, pass the msg through a JSON node first and it will be converted to an object

If you state what is generating that there may be a better way.

At a guess, this is coming from an HTTP request node? You can set the option in the HTTP Request node to parse the JSON automatically (avoiding the need for a JSON node)

---

<div class="post-metadata">

**Author:** ![satkey3](https://avatars.discourse-cdn.com/v4/letter/s/cc9497/32.png) [@satkey3](https://discourse.nodered.org/u/satkey3)\
**Post date:** [17 March 2026 18:05 UTC](https://discourse.nodered.org/t/how-to-extract-temperature-from-msg-payload/100583/6 "2026-03-17T18:05:35Z")

</div>

Hi,  
In used json to convert msg.payload from string to object:  
3/17/2026, 8:00:41 PM[node: debug 2](http://192.168.1.102:1880/#)msg.payload : Object

object

endpoint: object

payload: object

temperature: object

temperature: 67.4

My function  
const temperature = msg.payload.temperature  
let result = 0

if(temperature \> 60) {result=1}  
if(temperature \<= 60) {result=2}

msg.payload = result  
return msg;

But i get always result zero, the normal result in this case is 1 because 67 \> 60.  
Can you help me with the function?

---

<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:** [17 March 2026 18:12 UTC](https://discourse.nodered.org/t/how-to-extract-temperature-from-msg-payload/100583/7 "2026-03-17T18:12:56Z")

</div>

> [@satkey3](#):
>
> But i get always result zero, the normal result in this case is 1 because 67 \> 60.

You need to correctly select the message data using the hover button "copy value" because what you have pasted it is not clear what is what.

What I can see tho is that `temperature` is an `object` - you need to fully expand this until you see the numeric value then use the "copy path" button I showed you in the first message to ensure you get the right path.

Also, you can use `node.warn(msg.payload.temperature)` in the code to help you debug.

---

<div class="post-metadata">

**Author:** ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)\
**Post date:** [17 March 2026 19:34 UTC](https://discourse.nodered.org/t/how-to-extract-temperature-from-msg-payload/100583/8 "2026-03-17T19:34:19Z")

</div>

It looks like your `msg.payload` is a **string** , not an object yet — so you need to **parse the JSON first** , then access the **nested fields for temperature,** in a function node like this...

```auto
// Convert string to object
let data = JSON.parse(msg.payload);

// Extract temperature
let temperature = data.payload.temperature.temperature;

return temperature;

```

---

<div class="post-metadata">

**Author:** ![Sean-McG](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sean-mcg/32/54677_2.png) [@Sean-McG](https://discourse.nodered.org/u/Sean-McG)\
**Post date:** [19 March 2026 01:49 UTC](https://discourse.nodered.org/t/how-to-extract-temperature-from-msg-payload/100583/9 "2026-03-19T01:49:00Z")

</div>

> [@satkey3](#):
>
> if(temperature \> 60) {result=1}  
> if(temperature \<= 60) {result=2}

Also you should add some hysteresis, as this will likely lead to your output switching rapidly.

---

<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:** [17 June 2026 01:49 UTC](https://discourse.nodered.org/t/how-to-extract-temperature-from-msg-payload/100583/10 "2026-06-17T01:49:03Z")

</div>

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