Open Stalinko opened 1 year ago
It's documented that a "sequence containing a single value is considered equivalent to that value itself, and the output ... will be that value without any surrounding structure".
This behavior of jsonata is by design. You can force an array output for an expression returning one or more values by terminating the expression with square braces ($distinct(data.title[])
) and for zero or more values by wrapping it in square braces ($distinct([data.title])
)
Okay thanks @markmelville
I just wanted to let you know this behaviour is a real bug producer. Because in programming it's kinda a rule of thumb that if some function returns array then it should never return single entities.
Don't I know it! There are many issues both closed and open where that design decision is discussed. I searched around a little but couldn't find a good quote to share as to why the designers chose to do it that way.
@map
is exhibiting the same behavior.
This is basically the same bug as with
$filter
: https://github.com/jsonata-js/jsonata/issues/218Example:
My query:
Data:
Returns all good:
Data:
Returns:
Expected: