-
Notifications
You must be signed in to change notification settings - Fork 223
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
Inconsistent Behavior of [] between version 1.7.0 and 1.8.3 #462
Comments
The problem is that I don't think that change fully works. In JSONata 1.8.3, if we change the JSONata expression to
not
and I can't find an JSONata expression that uses |
The only solution I've found that will force nested arrays when working with array functions (e.g. $map, $filter) is the following:
Using [] at the end of the expression does not work the same as it does without functions involved. In function compositions, this means there isn't a way to force nested arrays as part of the output without wrapping with more functions to force arrays using the wrapping square brackets notation. At least, not that I'm aware of, anyway. |
This is stupid. Why would a function like $map() ever return anything other than an array? No other language does this. |
Thanks for the feedback. In common with XQuery, JSONata treats singleton sequences as equivalent to the value. But there is potentially an issue highlighted above (slightly more eloquently) that needs investigating. |
Just found this issue as I was expecting I found the workaround was to add
|
Shouldn't changes like this trigger a major version increment, as it breaks applications expecting the previous behavior? |
I ran into this problem while developing a function that adds a namespace to properties in a JSON. The function is recursive and traverses objects and arrays. However, when dealing with arrays that happen to contain another array, and that array was the only element, the function breaks. The issue can be seen by testing a simple JSON: If we apply this JSONata: It is not returning an array of arrays, but rather the first element of the outer array. This behavior is different than the "map" function in javascript, which returns [[1,2,3]]. The description for the "map" function: That description is incorrect for the test case I showed above. The map is returning the first ELEMENT of the array that was passed to it, not an array of arrays. I solved this problem using a "hack" but it works: Using the above logic, the function returns an array of arrays whether the outer array contains a singleton or not. Function and tester here: |
Cleary there is some hijinx introduced by the recent version? Can we get a confirmation that these changed behaviors are officially considered bugs? |
I have a PR that reverts the behaviour to how it was in v1.7 and added unit tests to ensure it stays that way. However, in order to not break the fix to #399 (which triggered this issue), I've reimplemented the logic such that if the array is explicitly constructed in the expression and marked to promote singleton sequences to arrays (using the |
I came here through a google search. Can we please update this behavior in JSonata main documentation https://docs.jsonata.org/higher-order-functions ? |
Consider the following input:
and JSONata expression:
singleArray[]
In version 1.7.0, the evaluated result is
but in 1.8.3 it is
Which evaluation is correct and why?
The text was updated successfully, but these errors were encountered: