Problem using $ifEmpty expression with two values

Describe the problem/error/question

I’m trying to write an expression to create a new JSON key:value inside an Edit Fields node.
I want to check if Value1 is empty, use it if it isn’t, and use Value2 if it is. Both existing values are strings.

The expression I have is:
{{ $ifEmpty( $json.Value1, “$json.Value2” ) }}

The problem is that when Value1 is empty, this returns as the literal string “$json.Value2”, not the contents of that respective value.

If I take the quotation marks away, I get a syntax error - it seems like they are a required part of the expression/function.

Is there a way around this? Or do I need to use this less elegant expression instead (which works, I just find it harder to read in more complex nested expressions)?:
{{ $if($json.Value1 == NULL, $json.Value2, $json.Value1) }}

It looks like your topic is missing some important information. Could you provide the following if applicable.

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