Change Object into payload

#1

Hello Again!

How do I change an object into msg.payload?

The node (homekit) spits out an object ```
{
"On": true
}

in msg.payload

I want to translate this to a simple msg.payload "true" or "false" to write to my MQTT server

thank you!!

0 Likes

#2

You can use a Change node set to Move msg.payload.On To msg.payload. Note that is Move, not Set.
However I have just noticed that you are also asking for it to be converted from a logic level to a string. Are you sure you need to do that? Try it without first and see what you get.
If you do need it as a string then instead set the change node to Set msg.payload, select J: as the To type and then
msg.payload.On ? "true" : "false"

0 Likes

#3

perfect! thank you Colin
(and you were right, I didn't need to convert to string)

follow up:
How do I do it the other way?
creating an object (On:true) from msg.payload?

The "move" change node doesn't work...

Martin

0 Likes

#4

Found it...

MQTT is sending a string, not a boolean...So i did a JSON convert first, now it works

0 Likes