Convert array to key/value pair

I have msg.payload as an array that I'd like to convert to a key/value pair.

debug shows msg.payload[1] : "25.6"

I'd like to create msg.payload.temperature: "25.6"

I'm using a "change" node to try and set msg.payload.temp to msg.payload[1] but it will not create the obejct.

I can however set msd.temp to msg.payload[1]

Where am I going wrong?

msg.payload is an array, you would need to convert it to an object.
so in change node
1 set msg.hold = msg.payload.
2 set msg.payload = {} (select json)
3 set msg.payload.temperature = msg.hold[1]

1 Like

or use move rather than set....

I thought that but as payload was being overwritten either would do.
Also if you use move the original payload data will be changed also, this will not be an issue if you don't need it later one.

That makes sense. I can’t change the engine on the plane while flying. Thanks for the advice.

1 Like

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