Manipulating Message Contents - A nudge in the right direction needed

Hi Oracles!!

I have a problem with the syntax needed to manipulate message contents...

Coming into a function node, I have a msg.payload of True or False, and a message topic-ie "powerOn"

I need to manipulate this info to give me an output of: "msg.payload.powerOn" where its value would be the boolean as received... The "powerOn" suffix is a variable depending on what is selected elsewhere on a dash....

Any help would be immensely appreciated!

TIA
Ed

Edit: For sake of clarity-

mysuffix = msg.topic
Data = msg.payload
msg.payload.(whatever is stored in mysuffix) = Data
return msg;
mysuffix = msg.topic
Data = msg.payload
msg.payload = {} // initialise msg.payload to an object
msg.payload[mysuffix] = Data
return msg

Spot On!!!

Thanks Heapzzzzz!!!

(One fullstop in the wrong place... I had: msg.payload.[mysuffix] = Data .... amongst about 30 other ways to screw it up)

Ed

1 Like

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