Cleaning the msg Object

Hi, i was suprised to see, how much information are in a "complete msg object".

Is there a simple trick to get rid of all the legacy (Modbus request, buffer, array...)

If I inject or switch a msg.payload (Leistung openwb or Übers ohne LP), I just want to inject the payload + topic and not all the previous objects from the beginning/source.


You can do it in a Function node like this:

let newmsg = {payload: msg.payload, topic: msg.topic};
return newmsg;

Why do you want to do this? Generally it is unnecessary and just wastes processor time.

1 Like

oh, I thought to carry all the old msg would cost processor load or the contents would interfere with nodes ?!
if that's not the case, then I'll leave it.

No, JavaScript uses references to data, so it is not copying the data each time. It usually makes no difference what is in the object. In fact removing data from an object uses processor time.

1 Like

One thing I would add to Colins response is while he is absolutely correct in what he says, there are scenarios where the msg will be cloned. For example, if you branch off to a debug (or any other node), the 1st msg will be a reference but subsequent messages will be cloned (See this blog post). One of the reasons I have long hoped for an in-line debug node.

That said, the amount of data you see in that msg is fairly inconsequential (probably in the region of microseconds to clone).

1 Like

Yes, that is true, I had temporarily forgotten that.

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