-
Notifications
You must be signed in to change notification settings - Fork 220
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
$map
does not return an array for input arrays of length 1
#708
Comments
$map
does not return an array on input arrays of length 1$map
does not return an array for input arrays of length 1
Temporary workaround for people struggling with this in production:
Playground link: https://try.jsonata.org/sa2yM0nj8 |
Another thing I noticed, if the input array is empty, the result is
from the docs is that the function returns an array in all cases, not just sometimes. Playground link: https://try.jsonata.org/pkveSyNDj |
I think your intuitions are correct. empty array -> empty array |
I also stumbled upon this weird behavior. Adding an array constructor at the end like I created a PR to fix that also in this case to be able to use the workaround: #714 However I would like to note that the current behavior of If this behavior is wanted, you could add an additional built-in function to return a singleton if explicitly requested, but not do that be default imho. |
According to the docs,
$map
should return an array. However, if the input data is an array containing exactly one element, it returns the value returned by the function passed to$map
as the second argument.Reproduction: https://try.jsonata.org/hW13DjVzw
In case the link stops working at some point in the future, here is the inlined version of the reproduction steps:
Data
Jsonata
Expected output
Actual output
The text was updated successfully, but these errors were encountered: