# Cleaning the msg Object

**URL:** <https://discourse.nodered.org/t/cleaning-the-msg-object/66167>\
**Category:** General\
**Created:** [8 August 2022 08:17 UTC](https://discourse.nodered.org/t/cleaning-the-msg-object/66167 "2022-08-08T08:17:10Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Becker](https://avatars.discourse-cdn.com/v4/letter/b/c77e96/32.png) [@Becker](https://discourse.nodered.org/u/Becker)\
**Post date:** [8 August 2022 08:17 UTC](https://discourse.nodered.org/t/cleaning-the-msg-object/66167/1 "2022-08-08T08:17:10Z")

</div>

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

 ![grafik](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/9/d95d73f1612575f4e9d8a07e7e446c8d9daa4ec5.png)  
 ![grafik](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/0/c09537ea5b2b7395e5972ff303b2a7ece56d283f.png)

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.

Greetings

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [8 August 2022 08:37 UTC](https://discourse.nodered.org/t/cleaning-the-msg-object/66167/2 "2022-08-08T08:37:46Z")

</div>

You can do it in a Function node like this:

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

```

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [8 August 2022 08:39 UTC](https://discourse.nodered.org/t/cleaning-the-msg-object/66167/4 "2022-08-08T08:39:26Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Becker](https://avatars.discourse-cdn.com/v4/letter/b/c77e96/32.png) [@Becker](https://discourse.nodered.org/u/Becker)\
**Post date:** [8 August 2022 08:52 UTC](https://discourse.nodered.org/t/cleaning-the-msg-object/66167/5 "2022-08-08T08:52:42Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [8 August 2022 09:10 UTC](https://discourse.nodered.org/t/cleaning-the-msg-object/66167/6 "2022-08-08T09:10:24Z")

</div>

> [@Becker](#):
>
> I thought to carry all the old msg would cost processor

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.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [8 August 2022 09:46 UTC](https://discourse.nodered.org/t/cleaning-the-msg-object/66167/7 "2022-08-08T09:46:54Z")

</div>

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](https://nodered.org/blog/2019/09/13/cloning-messages)). 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).

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [8 August 2022 10:59 UTC](https://discourse.nodered.org/t/cleaning-the-msg-object/66167/8 "2022-08-08T10:59:00Z")

</div>

> [@Steve-Mcl](#):
>
> there are scenarios where the msg will be clone

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [7 October 2022 10:59 UTC](https://discourse.nodered.org/t/cleaning-the-msg-object/66167/9 "2022-10-07T10:59:54Z")

</div>

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