# Cleaning a msg Object

**URL:** <https://discourse.nodered.org/t/cleaning-a-msg-object/18568>\
**Category:** General\
**Created:** [28 November 2019 18:26 UTC](https://discourse.nodered.org/t/cleaning-a-msg-object/18568 "2019-11-28T18:26:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sineos](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sineos/32/3440_2.png) [@Sineos](https://discourse.nodered.org/u/Sineos)\
**Post date:** [28 November 2019 18:26 UTC](https://discourse.nodered.org/t/cleaning-a-msg-object/18568/1 "2019-11-28T18:26:31Z")

</div>

Quite a lot IoT devices send multiple values, addresses, information etc in one message object.  
I have some cases where the elements later on start interfering with other functions since namespaces etc. are overlapping.

Today I'm solving this with a simple function node along the line of:

```auto
temp = msg.KeepThis
msg = {};
msg.payload = temp;
return msg;

```

Usually I would prefer to use the `change` node but deleting unwanted parts of a msg object is quite cumbersome on larger objects.

I wanted to ask if there is a best practice or if the `change` node could be enhanced to allow more flexible ways of cleaning out unwanted data, like:

- "Keep only" / "Delete all but"
- "Protect KeepThis" + "Delete all"
- Regex delete with look-ahead, look-behind

---

<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:** [28 November 2019 18:28 UTC](https://discourse.nodered.org/t/cleaning-a-msg-object/18568/2 "2019-11-28T18:28:11Z")

</div>

So many possible options. Or just use a simple function node as you have done...

---

<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:** [28 November 2019 22:13 UTC](https://discourse.nodered.org/t/cleaning-a-msg-object/18568/3 "2019-11-28T22:13:49Z")

</div>

You can, of course, just do  
`return {payload: msg.KeepThis}`
