jsonata-js/jsonata

How to handle undefined value

sureshssb07 opened this issue · 2 comments

Hi, We are using jsonata.net.native

We want to handle undefined value in final response.

Ex:
{
"One": 1,
"Two": 2
}

Query :
(
$finalOut := function($v)
{
$v = undefined ? 0 : $v
};
$finalOut('Three');
)

Actual output : undefined
Expected output : if it is undefined then final value needs to modify based on the business

I have tried $lookup(object, key) also but not working

Thanks in advance :)

We written some date conversion in custom function and when we execute the negative test cases, we are getting below exception

T0410: Argument 1 ('timestamp') of function toMillis should be String but incompatible value of type Undefined was specified

For that, how to handle undefined values in custom function?

Thanks in Advance

I got it , we need to use $type