# Delete whole msg

**URL:** https://discourse.nodered.org/t/delete-whole-msg/97237
**Category:** Feature Requests
**Tags:** change-node
**Created:** [23 May 2025 19:21 UTC](https://discourse.nodered.org/t/delete-whole-msg/97237 "2025-05-23T19:21:04Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [23 May 2025 19:21 UTC](https://discourse.nodered.org/t/delete-whole-msg/97237/1 "2025-05-23T19:21:04Z")

</div>

Hi,

I find myself needing to reset a msg completely inline with a flow. While I could use a function node, it seems a bit of an oversight not to be able to do this with a change node.

The idea would be to have a drop-down called "Reset msg". It would only really make sense to put it as the first entry of course (unless saving some msg content to a flow variable for later use) but still it would be really useful. Especially since you may not always be able to fully predict all of properties on a msg.

An alternate would be to allow wild-cards in the msg property name. so that you could have something like `msg.*`. In fact, that would be even more useful, especially if you could do something like `msg.xxxx*` to delete a bunch of similarly named properties.

Instead of a wildcard, you could have a regex.

Yet another potential option might be to allow a JSONata expression for the delete option where you return an array of entries.

---

<div class="post-metadata">

### Author: ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)
#### Post date: [23 May 2025 19:47 UTC](https://discourse.nodered.org/t/delete-whole-msg/97237/2 "2025-05-23T19:47:01Z")

</div>

Being able to have a "start over" node, I like - good call, I like it!

for now, I whipped up this. (I am adventurous this evening 😊)

```auto
[{"id":"99b68b4208b45e2f","type":"subflow","name":"Reset MSG","info":"","category":"","in":[{"x":50,"y":30,"wires":[{"id":"44c96ae25491502b"}]}],"out":[{"x":320,"y":135,"wires":[{"id":"44c96ae25491502b","port":0}]}],"env":[],"meta":{},"color":"#C0C0C0","icon":"font-awesome/fa-close"},{"id":"44c96ae25491502b","type":"function","z":"99b68b4208b45e2f","name":"function 2","func":"msg = {}\nreturn msg","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":165,"y":120,"wires":[[]]},{"id":"d25df8c32a9f06ba","type":"subflow:99b68b4208b45e2f","z":"2d7bf6e3.84c97a","name":"","x":300,"y":645,"wires":[["2fbc2f4203a938d1"]]},{"id":"8d675faadefabfaa","type":"inject","z":"2d7bf6e3.84c97a","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":110,"y":645,"wires":[["d25df8c32a9f06ba"]]},{"id":"2fbc2f4203a938d1","type":"debug","z":"2d7bf6e3.84c97a","name":"debug 2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":495,"y":645,"wires":[]}]

```

 ![Screenshot 2025-05-23 at 20.46.07](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/e/5e424ef5487fa0a03819464409dba14fcd774fd1.png)

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [23 May 2025 19:51 UTC](https://discourse.nodered.org/t/delete-whole-msg/97237/3 "2025-05-23T19:51:38Z")

</div>

Well yes, that is one way. 😃

Feels a bit overkill though. I don't think that it would be much to add to the delete option of the change node.

But thanks, I can obviously use your subflow for now. Though you can simplify it further:

```js
return {}

```

😉

---

<div class="post-metadata">

### Author: ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)
#### Post date: [23 May 2025 19:56 UTC](https://discourse.nodered.org/t/delete-whole-msg/97237/4 "2025-05-23T19:56:38Z")

</div>

But I do agree, being able to Nuke the object will be a nice addition in a change Node.  
I did try tricking it, but nope, it wasn't happening

---

<div class="post-metadata">

### Author: ![mikefila](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mikefila/32/95223_2.png) [@mikefila](https://discourse.nodered.org/u/mikefila)
#### Post date: [23 May 2025 20:25 UTC](https://discourse.nodered.org/t/delete-whole-msg/97237/5 "2025-05-23T20:25:56Z")

</div>

Am I missing something, if I need to clear a message path, I set the message to an empty object.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/4/94baf934881b6495718e18fa97efdc7a83339459.png)

That is the same message, the second was sent through a change node.

---

<div class="post-metadata">

### Author: ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)
#### Post date: [23 May 2025 20:34 UTC](https://discourse.nodered.org/t/delete-whole-msg/97237/6 "2025-05-23T20:34:04Z")

</div>

Yes - we get that.

But to clear the object, one needs to use a `function` node currently, without getting into the weeds...  
This involves creating a Javascript Virtual Machine (that the function nodes creates), and this creates overheads in doing so - I believe

The `change` node, has the ability to manipulate the object (`msg`) - without creating a VM, and the suggestion here is to extend the ability to clear the object, without creating a VM.

Note: this is about the whole `msg` object, not a property inside of it (like `payload`). -which is a property

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [23 May 2025 20:39 UTC](https://discourse.nodered.org/t/delete-whole-msg/97237/7 "2025-05-23T20:39:39Z")

</div>

This was discussed a few years back [Add a way to create a completely new object (change node enhancement?)](https://discourse.nodered.org/t/add-a-way-to-create-a-completely-new-object-change-node-enhancement/53167)

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [23 May 2025 21:09 UTC](https://discourse.nodered.org/t/delete-whole-msg/97237/8 "2025-05-23T21:09:26Z")

</div>

Hmm, well spotted. But that seems to have been massively over-thought.

Node-RED automatically recreates the msg id as far as I can tell and if I'm asking to delete the whole msg, there has to be an expectation that this is what I really want.

So I don't think that _any_ of the other properties should be kept.

If necessary, there should be 2 different options:

- Delete all the msg content - just nukes all the content.
- Reset the msg content - which retains the things that Dave and Nick were referring to.

Obviously, the former is easier to implement.

---

<div class="post-metadata">

### Author: ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)
#### Post date: [24 May 2025 05:17 UTC](https://discourse.nodered.org/t/delete-whole-msg/97237/9 "2025-05-24T05:17:13Z")

</div>

This would be a welcome addition, i often encounter this issue when using http request/sql nodes where properties live outside payload.

However, somewhere I would like to keep a single or multiple properties but remove the rest. Currently, i am delete all individual properties which is cumbersome.

---

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [24 May 2025 05:21 UTC](https://discourse.nodered.org/t/delete-whole-msg/97237/10 "2025-05-24T05:21:47Z")

</div>

To add my bit,

Sometimes I think I have been in a similar/same situation and it would be handy.

As stated, I use a `function` node to create a new message.  
(sorry, I'm rambling now.)

But I do agree it would be a nice thing to have.

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [24 May 2025 10:25 UTC](https://discourse.nodered.org/t/delete-whole-msg/97237/11 "2025-05-24T10:25:57Z")

</div>

> [@bakman2](#):
>
> However, somewhere I would like to keep a single or multiple properties but remove the rest. Currently, i am delete all individual properties which is cumbersome.

I did think about an option that would take an array of properties to remove. That could also be nice.

Obviously, there is a danger here of going down too many rabbit holes again. So trying to keep ideas simple, at least for now.

I know I'm going to regret this, but I've never actually done a PR for Node-RED as I've always been put off by the complexity as well as my lack of knowledge of how to do test scripts. But maybe this might be the time?

Would welcome some confirmation from the core devs though before trying to continue.

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [25 May 2025 06:56 UTC](https://discourse.nodered.org/t/delete-whole-msg/97237/12 "2025-05-25T06:56:38Z")

</div>

I did create a node [node-red-contrib-remap](https://flows.nodered.org/node/node-red-contrib-remap) that may help. Configuration is usually a two step process, but it can be set to block all or pass all by default. Once you have run it once you can then configure it to pass, remove, or remap individual properties.

 ![remap](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/1/41f339eae4795ea3e892c1266b653f41bca18aad.png)

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [25 May 2025 11:08 UTC](https://discourse.nodered.org/t/delete-whole-msg/97237/13 "2025-05-25T11:08:20Z")

</div>

And I even have that installed on my dev instance but not live! Thanks for the reminder Dave. I've now added it to my flows collection of useful nodes. 🙂

---

<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: [24 July 2025 11:08 UTC](https://discourse.nodered.org/t/delete-whole-msg/97237/14 "2025-07-24T11:08:38Z")

</div>

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