-
Notifications
You must be signed in to change notification settings - Fork 259
Description
I am working on a Java implementation of the JSONata engine, and I'm struggling to understand JSONata's treatment of singleton arrays...
From http://docs.jsonata.org/complex.html:
Within a JSONata expression or subexpression, any value (which is not itself an array) and an array containing just that value are deemed to be equivalent.
Firstly, if so - why does the following hold?
[1] = 1 => false (should this not be true?)
So, outside of the '=' operator itself, I suspect the singleton/primitive equivalence is effectively achieved by "unwrapping" singleton arrays as they are referenced by expressions.
I see the following behaviour:
{'a': 1 }.a => 1
{'a': [1] }.a => 1
{'a': [[1]] }.a => 1
{'a': [[[1]]] }.a => [1]
{'a': [[[[1]]]] }.a => [[1]]
so it seems to me that JSONata is applying (at most) two levels of flattening to nested singleton arrays pulled out of an associative array via a path. Why 2? Why does it not completely flatten the output array in cases like this?
Next, if I wrap the statements above in an array constructor, I see the the following:
[{'a': 1 }.a] => [1]
[{'a': [1] }.a]=> [1]
[{'a': [[1]] }.a] => [1]
these results seem reasonable (given that the embedded statement returns 1 in those cases), however:
[{'a': [[[1]]] }.a] => [1]
should this not be [[1]]? (given than the statement inside the array constructor evaluates to [1]?