NODE-RED • JSON

How to extract a JSON value in Node-RED

When a Node-RED message contains a JSON object, the data is commonly available under msg.payload. If the payload contains temperature, a Function node can read it with msg.payload.temperature.

Example

{ "temperature": 32.5, "status": "ON" }

To replace the payload with the temperature value:

msg.payload = msg.payload.temperature;
return msg;

For nested data, follow the object structure. For example, msg.payload.device.name accesses the name property inside device.

ADVERTISEMENT

Use the JSON Explorer

Paste your real payload into the free JSON Explorer to inspect fields and generate the corresponding Function code.