# Change node \> Delete from array (JSON)

**URL:** <https://discourse.nodered.org/t/change-node-delete-from-array-json/14559>\
**Category:** General\
**Created:** [20 August 2019 17:21 UTC](https://discourse.nodered.org/t/change-node-delete-from-array-json/14559 "2019-08-20T17:21:27Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![hobojoe720](https://avatars.discourse-cdn.com/v4/letter/h/76d3ee/32.png) [@hobojoe720](https://discourse.nodered.org/u/hobojoe720)\
**Post date:** [20 August 2019 17:21 UTC](https://discourse.nodered.org/t/change-node-delete-from-array-json/14559/1 "2019-08-20T17:21:27Z")

</div>

Hey Guys,

New to Node-Red so sorry if this is basic. I have a simple flow, that fetches from an API and the result is a JSON object which is summarised below.

```auto
{ "results": [ 
    {"url": "https://myurl", "id": 1}, 
    {"url": "https://myurl", "id": 2}, 
    {"url": "https://myurl", "id": 3} ],
"next_page": "",
"count": 3
}

```

Reading through: [https://nodered.org/docs/user-guide/messages](https://nodered.org/docs/user-guide/messages) it says that the easiest method of working with this object is to use "Change" as I want to drop "url" from each entry in the array. It is worth noting that the number of objects, is much higher than just 3, and there are more fields than just url to drop.

If i set "change" to "delete msg.payload.results[0].url" it drops it from the first result obviously, but cant find a way to make it do it for all of them.

Thanks in advance

---

<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:** [20 August 2019 17:45 UTC](https://discourse.nodered.org/t/change-node-delete-from-array-json/14559/2 "2019-08-20T17:45:37Z")

</div>

You can use a jsonata expression  
payload.results.url

---

<div class="post-metadata">

**Author:** ![hobojoe720](https://avatars.discourse-cdn.com/v4/letter/h/76d3ee/32.png) [@hobojoe720](https://discourse.nodered.org/u/hobojoe720)\
**Post date:** [21 August 2019 07:52 UTC](https://discourse.nodered.org/t/change-node-delete-from-array-json/14559/3 "2019-08-21T07:52:32Z")

</div>

Is this still using the Change node? As when I use the above it doesn't work.  
As per the screenshot, url is still there.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/2/22b793e8a8464bcc15f9c5ba2c5d8329724191ef.png)

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [21 August 2019 08:01 UTC](https://discourse.nodered.org/t/change-node-delete-from-array-json/14559/4 "2019-08-21T08:01:40Z")

</div>

Sometimes a function is easier...

```auto
msg.payload.results.forEach(function(v){ delete v.url });
return msg;

```

---

<div class="post-metadata">

**Author:** ![hobojoe720](https://avatars.discourse-cdn.com/v4/letter/h/76d3ee/32.png) [@hobojoe720](https://discourse.nodered.org/u/hobojoe720)\
**Post date:** [21 August 2019 08:38 UTC](https://discourse.nodered.org/t/change-node-delete-from-array-json/14559/5 "2019-08-21T08:38:29Z")

</div>

Definitely easier when you know the language. Time to start learning Javascript

---

<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:** [21 August 2019 09:03 UTC](https://discourse.nodered.org/t/change-node-delete-from-array-json/14559/6 "2019-08-21T09:03:32Z")

</div>

You are right, I failed to realise that there is no jsonata available for the delete option 😬

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [21 August 2019 09:19 UTC](https://discourse.nodered.org/t/change-node-delete-from-array-json/14559/7 "2019-08-21T09:19:48Z")

</div>

In the change node you can use this to delete the url  
`payload ~> | results | {} , ['url']|`  
see [https://docs.jsonata.org/control-operators#transform-](https://docs.jsonata.org/control-operators#transform-) and thank @shrickus 🤩 for pointing me to that feature of jsonata

---

<div class="post-metadata">

**Author:** ![hobojoe720](https://avatars.discourse-cdn.com/v4/letter/h/76d3ee/32.png) [@hobojoe720](https://discourse.nodered.org/u/hobojoe720)\
**Post date:** [21 August 2019 09:46 UTC](https://discourse.nodered.org/t/change-node-delete-from-array-json/14559/8 "2019-08-21T09:46:44Z")

</div>

So I started with @ukmoose's response worked perfect.  
I actually changed it up instead and after some leaning went with a different approach, and that was to choose which values to keep rather than which ones to delete using map.

```auto
msg.payload.results = msg.payload.results.map(
    i => ({
        id: i.id,
        subject: i.subject.substring(0,99),
        status: i.status.substring(0,9),
        created_at: i.created_at,
        description: i.description.substring(0,99)
    })
)

return msg;

```

This cleans it up perfectly. Different from what I originally asked, but actually works better for my use case.

---

<div class="post-metadata">

**Author:** ![shrickus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shrickus/32/517_2.png) [@shrickus](https://discourse.nodered.org/u/shrickus)\
**Post date:** [29 August 2019 12:45 UTC](https://discourse.nodered.org/t/change-node-delete-from-array-json/14559/9 "2019-08-29T12:45:33Z")

</div>

> [@hobojoe720](#):
>
> ... that was to choose which values to keep rather than which ones to delete using map

Another perfectly valid way to go, especially when you don't know what other fields _may_ be present...

FWIW, the analogous way to build an array of pared-down objects using JSONata would be:

```auto
    payload.results[].{
        "id": id,
        "subject": subject.$substring(0,99),
        "status": status.$substring(0,9),
        "created_at": created_at,
        "description": description.substring(0,99)
    }

```
