How to get an empty array after IF and MERGE?

I use Merge and If nodes to get Notion items according to their status like done. I need to use this data, even if there’s 0 items (i will output this 0 further)

But I found out that if there’s no items for Merge or If output, then there is no data flow, even the empty array []

What should I do in this situation?

Here the data flow interrupts after there’s 0 items with the “postponed” status. I would send this information “0 items found” later in Paragraph JSON node:

Hey @artildo,

In the settings for the node most of them contain an “always output data” option. Give that a bash on the merge and see if it does what you want.

1 Like

Thank you, @jon

Yes, this works. It gives another problem - the output array has thes the length of 1 (I need it 0). So a specific rule is needed to catch the [{}] case. I came up with this:

let total_items;

if (items.length === 1 && JSON.stringify(items[0]) === "{\"json\":{}}") {
    total_items = 0;
  } 
else {
    total_items = items.length;
  };

return [
  {json: {total: total_items}
  }
]
1 Like

That is the downside you are forced to work with the output provided and put in checks to make sure it is what you are after.

Sounds like you have a solution though which is always good.

Yes, works like charm:

1 Like