Hey!
How can I leave only columns with values other than null in the next node of functions?
In this set node, at the output, there are all three types: string, number and boolean. The number type can be null - it does not need to be passed on.
Check the example below:
{
"nodes": [
{
"parameters": {},
"name": "Start",
"type": "n8n-nodes-base.start",
"typeVersion": 1,
"position": [
250,
300
]
},
{
"parameters": {
"functionCode": "return [\n {\n json: {\n name: 'ricardo',\n age: null,\n }\n },\n {\n json: {\n name: null,\n age: 30,\n }\n }\n]"
},
"name": "Function",
"type": "n8n-nodes-base.function",
"typeVersion": 1,
"position": [
520,
300
]
},
{
"parameters": {
"functionCode": "const results = []\n\nfor (const item of items) {\n const object = {};\n for (const key of Object.keys(item.json)) {\n if (item.json[key] !== null) {\n object[key] = item.json[key]\n }\n }\n results.push({ json: object })\n}\n\nreturn results;"
},
"name": "Function1",
"type": "n8n-nodes-base.function",
"typeVersion": 1,
"position": [
760,
300
]
}
],
"connections": {
"Start": {
"main": [
[
{
"node": "Function",
"type": "main",
"index": 0
}
]
]
},
"Function": {
"main": [
[
{
"node": "Function1",
"type": "main",
"index": 0
}
]
]
}
}
}
2 Likes