How to get rid of a few elements in an array?

Hi!

Would you please tell me how to get rid of a few elements in an array?
Remove unnecessary elements.

I have an array:

[
{
"Archived": false,
"StartISEmpty": true,
"DueISEmpty": true,
"ClosedISEmpty": true,
"Task ID": "28kjmwb",
"Folder ID": "10838920",
"List ID": "21391085",
"Status ID": "c10838920_eHzay4Wd",
"Space ID": "2275966",
"Task Name": "task",
"Start Datetime": null,
"Date Updated": "2022-03-16T19:14:12+03:00",
"Due Datetime": null,
"Tags": [
],
"Folder Name": "Неосновное",
"List Name": "Clean PC",
"Date Closed": null,
"Status Name": "3 квартал",
"Status Color": "#af7e2e",
"Priority": null,
"Time spent": "00:00:00",
"Time estimate": "00:00:00"
}
]

I need to get one like this:

[
{
"Archived": false,

"Task ID": "28kjmwb",
"Folder ID": "10838920",
"List ID": "21391085",
"Status ID": "c10838920_eHzay4Wd",
"Space ID": "2275966",
"Task Name": "task",
"Start Datetime": null,
"Date Updated": "2022-03-16T19:14:12+03:00",
"Due Datetime": null,
"Tags": [
],
"Folder Name": "Неосновное",
"List Name": "Clean PC",
"Date Closed": null,
"Status Name": "3 квартал",
"Status Color": "#af7e2e",
"Priority": null,
"Time spent": "00:00:00",
"Time estimate": "00:00:00"
}
]

How to get rid of these (3 items):

“StartISEmpty”: true,
“DueISEmpty”: true,
“ClosedISEmpty”: true,

???

Thank you!

Hi Mikhail,

I would use the Set node to map over the elements you want to keep. So add a String value for each item you want to keep, and then use the expression editor to call on these items. Then, at the top of the Set node, use the Keep Only Set toggle to eliminate everything else. Let me know if this helps!

1 Like

I thought maybe there was a quicker way. With a Function node and a line of code - like: Delete(“StartISEmpty”,“DueISEmpty”,“ClosedISEmpty”)

Thank you, @djangelic so much for your reply!

I’m starting to learn how to use the Function node and I figured out how to accomplish it via your method, here is the example. Make sure you are on the latest version of n8n or the first node won’t work:

3 Likes
delete items[0].json.StartISEmpty;
delete items[0].json.DueISEmpty;
delete items[0].json.ClosedISEmpty;
return items;

Just perfect! :grinning: That’s what I was thinking, but I’m not an IT person.

Thank you so much @djangelic !

2 Likes

My pleasure! Have fun automating!

1 Like