cancel
Showing results for 
Search instead for 
Did you mean: 

Number is equal ""(empty string)?

ionutbarna
New Contributor II

Hi there,

Can someone explain to me why the following expression generates true as a result:
I have the following pipeline:
pipeline

In JSON Generator I have:

{
  "field": null
}

AutoPrep config:
autoprep

Data type is set to a number; if null, 0 (zero) will be the result value.

Mapper:
mapper

Shouldn’t this validate as false? The field is a number and has the value 0.

The result after validation:

result

1 REPLY 1

achoudhary
Employee
Employee

Hi ionutbarna,

The SnapLogic Expression’s == works the same as == in a JavaScript,

For the expression 0 == "", the left operand is a Number and the right is a String.

In this case, the right operand is coerced to the type Number: 0 == Number("").

This results in 0 == 0 and thus true.

Here is the output from the same expression in JavaScript console:

Screen Shot 2022-10-24 at 9.31.23 AM