Object manipulation

This will be a no-brainer for 99% of people but I am lost at the moment. Simple task.

Via MQTT I get messages from a program (p4d). I receive them and have them converted to JSON. All messages have properties:

{"id":"UD:0x01","type":"UD","name":"Heizungsstatus","unit":"zst","state":"off","value":19,"action":"CHANGE"}

I want to store this in Influx with the measurement being "name" (Heizungsstatus) and the value being the value (19). I believe the msg.property I have to feed to influx out is

{"Heizungsstatus","19"}

How do I manipulate the msg properly? And of course I would need this to be dynamic and work with all combinations for name/value. I would love to filter these then later on to only allow certain names/measurements only...

I guess you mean you want to use the payload name as a key and the value property as its value?

In a function node:

msg.payload = {
   [msg.payload.name]: msg.payload.value
}
return msg

Possible via change node too with and without JSONata

Sometimes things are so simple. Thanks so much!

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