Issue with if statement

Describe the problem/error/question

I have noticed that if I put an if statement in a node, the output of the first node is changed to whatever the if statement is evaluating against. For example, if I have a set node and just put the value of 50 in (Set Test in the shared flow). Then I do another node after that (If Statement in the flow) and have it evaluate if Test = 1 then it will always evaluate to true but should be false because 50 doesn’t equal 1. I can change the values to anything and it will evaluate incorrectly.

What is the error message (if any)?

No Error messages. Just incorrect output.

Please share your workflow

Share the output returned by the last node


Please note that the set node in the image above actually has the value of 50 passed through not 1.

Information on your n8n setup

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

actually, it looks like the previous node is either gliching out or setup wrong, bc “Test” is being set to 1

Yeah, I’m not sure that’s supposed to happen. :thinking:
If you open the IF node, then go back and open the Edit Field node, the Edit Field node field “Test” is now set to 1 instead of 50.

That said, I can imagine this being useful. :slightly_smiling_face:

It does look like I had the formula wrong. Instead of {{ $if($json.Test = 1,“Is 1”,“Is Not 1”) }} it should have had {{ $if($json.Test == 1,“Is 1”,“Is Not 1”) }} (a double equal sign). But it is still weird when you go back to the original node it displays 1 instead of 50.

Yes, this is weird!

Actually, you can set and manipulate any value using this expression:

{{ $json.name = "new value" }}

This will overwrite its value.

Not sure if this is a bug or expected behavior!

This could be used to create workflow variables.

Hmm, can we also use it in loops as dynamic variables? :smiley:

1 Like

Yeah, if this turns out be unintentional, we should make it a feature request.

1 Like

I think it’s just standard JavaScript assignment.

The = sign is assignment, so:

$json.name = “new value”

assigns “new value” to $json.name, it doesn’t compare it.

For comparision, you should use == and your $json.name variable will be unchanged.