Parsing an object, when part of it isn't "object-y"

Received MQTT message is converted using the JSON node and gives this output:

tele/Hetty/SENSOR : msg.payload : Object
  Time: "2020-06-26T20:36:58"
  DS18B20-1: object
    Id: "030197946C6B"
    Temperature: 21.6

I can extract the ID value, because it's enclosed in " ". I can't seem to extract the 'Temperature' value, it isn't enclosed in quotes...I get 'undefined' errors.

Question: how to handle the '21.6' value which is formatted differently to the other values...

How are you trying to access it? The fact it doesn't have quotes just means its value is a number rather than a string - it doesn't affect how to access it.

To get to the ID, you would use msg.payload["DS18B20-1"].Id.
Similarly, the Temperature is msg.payload["DS18B20-1"].Temperature.

This page in the docs describes how you can use the Debug sidebar to get the path to any message element -

I had been using the 'path' button, which helped with understanding the Object structure.

My main issue seems to have been using the switch node to select on string "DS18B20-1" - when using the string option, don't need the quotes...

I now have an output message containing just 'Id' and 'temp value'. That'll do for now!

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