Handling null, undefined values

Describe the problem/error/question

Is there a better way to handle undefined values than a ternary? It is annoying having to do this for every value.

What is the error message (if any)?

Please share your workflow

{{ $json.fieldName ? $json.fieldName : β€œβ€ }}

(Select the nodes on your canvas and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow.)

Share the output returned by the last node

Information on your n8n setup

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

Hi @spencerbf, it depends a bit on the exact context you want to handle such values in, but in general I like to use what’s called short-circuiting: {{ $json.fieldName || "" }}. Here is an example workflow:

2 Likes

@MutedJam Sorry for the delay, i have not been on n8n for the last week. Thanks for your help and response! Much appreciated.

1 Like

thanks @MutedJam.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.