I have an input data that as an array for each item. The array may be empty.
[
{
json: {
somearray: [],
}
},
{
json: {
somearray: [1,2],
}
}
]
I’m trying to check if the array is empty or not. When I connect IF node and open variable selector, I cannot select the key of the array (“somearray” above) if the array of the first input data is empty. Is that a bug or expected behavior?
That does not happen when the array is not empty.
Also, if I set manually the expression of IF condition as “{{$json[“id”].length}}”, the workflow seems to work fine even when the array is not selectable in variable selector.
{
"nodes": [
{
"parameters": {
"conditions": {
"number": [
{
"value1": "=null {{$json[\"id\"].length}}",
"operation": "smallerEqual"
}
]
}
},
"name": "IF",
"type": "n8n-nodes-base.if",
"typeVersion": 1,
"position": [
660,
290
]
},
{
"parameters": {},
"name": "Start",
"type": "n8n-nodes-base.start",
"typeVersion": 1,
"position": [
250,
300
]
},
{
"parameters": {
"functionCode": "return [\n {\n json: {\n id: [1],\n }\n },\n {\n json: {\n id: [1,2],\n }\n }\n];\n\n"
},
"name": "Function",
"type": "n8n-nodes-base.function",
"typeVersion": 1,
"position": [
460,
290
]
},
{
"parameters": {
"conditions": {
"number": [
{
"value1": "=null {{$json[\"id\"].length}}",
"operation": "smallerEqual"
}
]
}
},
"name": "IF",
"type": "n8n-nodes-base.if",
"typeVersion": 1,
"position": [
660,
290
]
}
],
"connections": {
"Start": {
"main": [
[
{
"node": "Function",
"type": "main",
"index": 0
}
]
]
},
"Function": {
"main": [
[
{
"node": "IF",
"type": "main",
"index": 0
}
]
]
}
}
}