Stop node from sending null objects

Describe the issue/error/question

Example in the photo… When preparing a node with data sometimes I do not have that data available.
And instead of loading an empty field into the node, my expression will load null and pass a null object to the receiving API.

Is it possible to stop the node from sending null objects?

What is the error behavior?

The receiving service had valid data for said record, but because a null object was passed that valid data is nulled out.

Information on your n8n setup

  • n8n version: .179

You can add || undefined.

So for for example:

{{ $ || undefined }}
1 Like

Awesome thanks! HMMM. what is that OR operator going to do if there are multiple valid options?

for example {{$ || $json.name2 || undefined}}

In your example it should still resolve to undefined if both variables resolve to null or undefined. If any of them resolves to something else it will use that one.

1 Like

Yes, what will the behavior be if both name and name2 resolve to valid strings?

The first one that has a value will be returned. So in this case name.

1 Like

@jan By experimentation from what I can tell…
for strings {{ $ || undefined}} = $
for integers {{undefined || $json.number }} = $json.number
for bools {{undefined || $json.bool }} = $json.bool

@jan This looks interesting…

Hmmm maybe this is more accurately a situation where if a value is undefined then
{{undefined || “default value”}} is invalid undefined takes the priority.

No I keep testing and cannot find a solid pattern. Or the pattern I find is non functional.
I think this might be a bug.

That makes it impossible or very difficult to reliably set default values.