Move multiple objects

I'm using a node-red-contrib-simpletime node which adds a series of objects to the message based on what options I have ticked. For example, I am adding msg.mydate, msg.mymonth, msg.myday and so on. There are 10 in total.

After this step the message heads to a join node where I need all objects to be under the msg.payload object otherwise they get lost when joining using key/value object.

Right now I have a change node moving each object to the payload one by one and I update it each time I activate or deactivate an option. For example, I move msg.mydate to msg.payload.mydate and so on (10 times over).

Can you do a move (as a single operation compared to a set & delete) in a function node? Can you do a move based on a wildcard e.g. move msg.my* to msg.payload.my*?

Thanks for the assist.

Kinda. You could loop through the keys of the msg object & if the key starts with my then add that to the payload object.

Alternatively, would it not be enough to simply assign msg to the property payload of a new msg object? E.g.

return { payload : msg }

Alternatively, you could probably do it with a change node and JSONata (but I don't know how)

Lastly, you could request to the author for this feature (assuming it's not already a feature - I don't know, I don't use it)

Thank you @Steve-Mcl...

return { payload : msg }

... was exactly what I was looking for!

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