Return first or other value in expression

Hello,

I am returning values ​​from an HTTP request.
In some cases the value is not in the same place:

that is :

1st case:
value1 = MYVALUE1
value2 = MYVALUE2
value3 = null
return :
“data”: MYVALUE1

2nd case:
value1 = null
value2 = MYVALUE2
value3 = null
return :
“data”: MYVALUE2

3rd case:
value1 = null
value2 = null
value3 = MYVALUE3
return :
“data”: MYVALUE3

I tried this expression but it doesn’t work in my case it seems:

{{$node[“TEST”].json[“value1”] || $node[“TEST”].json[“value2”] || $node[“TEST”].json[“value3”] }}

An idea ?

Try using ?? instead of ||

|| operator will check if on the left is false value (i.e. 0 is false)
?? operator will check if on the left is null / undefined value
ref: Nullish coalescing operator (??) - JavaScript | MDN

If not word check what is in null value it might be for example string "null" then it won’t be working as expected.

4 Likes

Thank you very much! That’s what I was looking for. I learned again thanks to you! :slight_smile: