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
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) 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.

more tips and tricks
I recommend watching this playlist: Node-RED Essentials. 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.
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
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 ↓
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.
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)
Hi,
In used json to convert msg.payload from string to object:
3/17/2026, 8:00:41 PMnode: debug 2msg.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?
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.
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...
// Convert string to object
let data = JSON.parse(msg.payload);
// Extract temperature
let temperature = data.payload.temperature.temperature;
return temperature;
1 Like
Also you should add some hysteresis, as this will likely lead to your output switching rapidly.