Extract values from complex payload

I'm a relative newbie to Node-Red, but capable developer in some other languages. What would be the best way to approach extracting the Temprature and Humidity values from the following payload?

The payload is being recieved over MQTT with AEDIS.


Hi, firstly, I edited your post to correctly format code (it was being corrupted by forum formatting as you used "quote" button not the "code" </> button :slight_smile:

Not to be too presumptuous but I guess you are not familiar with JSON?

So a small lesson on JS objects and their equivalent string representation (AKA JSON)...

Your payload is a string/JSON (due to the Output setting on the MQTT node). You could attempt some complex splits and loops etc - but - as it is JSON (JavaScript Object Notation) - just let JS do its thing - turn that JSON back into a JS Object! (if you dont know what I mean, it'd be worth reading up - will help you greatly in node-red knowing the difference)

So first off, change your MQTT IN to...
... once you have turned the JSON back into an object, you will be able to simply "copy path" to any item in the object on the debug sidebar

There’s a great page in the docs that will explain how to use the debug panel to find the right path to any data item.



The data you posted is not quite valid JSON (missing " after "dev_id":"mydevid)

Do you have control over what is generating this bad JSON? If so, i recommend fixing this at the src - it will make your life soo much easier. The alternative is probably a regex or string parsing (not pretty and not necessary if JSON is correctly formatted)

or perhaps this was simply a copy/paste error?

Hope that helps.

1 Like


That is hands down the best reply I have ever had to a question I've posted. Thank you for being excellent!.

Showing the JSON path is actually a really great feature too.

I'll keep plugging away. I think that's exactly what I needed to get going. Thank you.

Haha - excellent response :smiley: .

You're welcome.

Happy learning :+1:

1 Like