Version: observed on 2.6.4 and reproduced by the HCL Universal Orchestrator team on the 3.x line (Jackson 3 build).
Summary
When the condition of cond ? a : b evaluates to a non-empty object or a non-empty array, JSONata4Java returns the condition value instead of evaluating a branch. #127 fixed the case where the condition is a string field (key ? 1 : 2); the object and array cases still misbehave. The reference implementation (jsonata-js 2.x) applies the $boolean() casting rules: a non-empty object or array is true, an empty array is false.
Reproduction (input {})
| expression |
jsonata-js |
JSONata4Java |
{'k': 1} ? 'YES' : 'NO' |
"YES" |
{"k":1} |
[1] ? 'YES' : 'NO' |
"YES" |
[1] |
$match('HCL1', /^HCL[0-9]+$/) ? 'YES' : 'NO' |
"YES" |
{"match":"HCL1","index":0,"groups":[]} |
$match('x', /^HCL[0-9]+$/) ? 'YES' : 'NO' |
"NO" |
[] |
'abc' ? 'YES' : 'NO' |
"YES" |
"YES" (correct) |
$boolean($match('HCL1', /^HCL[0-9]+$/)) ? 'YES' : 'NO' |
"YES" |
"YES" (correct) |
$type('HCL1') = 'string' and $match('HCL1', /^HCL[0-9]+$/) ? 'YES' : 'NO' |
"YES" |
"YES" (correct) |
Expected
Per https://docs.jsonata.org/programming#conditional-logic the condition is cast with the $boolean rules, so the first four rows should return "YES", "YES", "YES", "NO".
Impact
$match(x, /re/) ? a : b is the natural way to write an allow-list; on JSONata4Java it silently yields the match object (or an empty array) in place of the intended branch value, with no error.
Workaround
Wrap the condition in $boolean(), use $contains(x, /re/), or combine with a boolean via and.
Version: observed on 2.6.4 and reproduced by the HCL Universal Orchestrator team on the 3.x line (Jackson 3 build).
Summary
When the condition of
cond ? a : bevaluates to a non-empty object or a non-empty array, JSONata4Java returns the condition value instead of evaluating a branch. #127 fixed the case where the condition is a string field (key ? 1 : 2); the object and array cases still misbehave. The reference implementation (jsonata-js 2.x) applies the $boolean() casting rules: a non-empty object or array is true, an empty array is false.Reproduction (input
{}){'k': 1} ? 'YES' : 'NO'{"k":1}[1] ? 'YES' : 'NO'[1]$match('HCL1', /^HCL[0-9]+$/) ? 'YES' : 'NO'{"match":"HCL1","index":0,"groups":[]}$match('x', /^HCL[0-9]+$/) ? 'YES' : 'NO'[]'abc' ? 'YES' : 'NO'$boolean($match('HCL1', /^HCL[0-9]+$/)) ? 'YES' : 'NO'$type('HCL1') = 'string' and $match('HCL1', /^HCL[0-9]+$/) ? 'YES' : 'NO'Expected
Per https://docs.jsonata.org/programming#conditional-logic the condition is cast with the $boolean rules, so the first four rows should return "YES", "YES", "YES", "NO".
Impact
$match(x, /re/) ? a : bis the natural way to write an allow-list; on JSONata4Java it silently yields the match object (or an empty array) in place of the intended branch value, with no error.Workaround
Wrap the condition in
$boolean(), use$contains(x, /re/), or combine with a boolean viaand.