Repository: jsonata-js/jsonata (js)

Issue:
Inconsistent Behavior of [] between version 1.7.0 and 1.8.3
Consider the following input:
```
{
  "singleArray": [{"foo":"bar"}]
}
```
and JSONata expression:
`singleArray[]`

In version 1.7.0, the evaluated result is 
```
[
  {
    "foo": "bar"
  }
]
```
but in 1.8.3 it is
```
[
  [
    {
      "foo": "bar"
    }
  ]
]
```
Which evaluation is correct and why?

Pull request:
fix regression with singleton sequence of array type
Change the logic for promoting a singleton sequence of array type into an array of arrays.  The logic was put in to fix issue #399 but caused an unintended regression as described in issue #462.

resolves #462

Signed-off-by: andrew-coleman <andrew_coleman@uk.ibm.com>

Patch:
diff --git a/src/jsonata.js b/src/jsonata.js
index e1d6092..1a0488a 100644
--- a/src/jsonata.js
+++ b/src/jsonata.js
@@ -219,7 +219,8 @@ var jsonata = (function() {
         }
 
         if(expr.keepSingletonArray) {
-            if(!isSequence(resultSequence)) {
+            // if the array is explicitly constructed in the expression and marked to promote singleton sequences to array
+            if(Array.isArray(resultSequence) && resultSequence.cons && !resultSequence.sequence) {
                 resultSequence = createSequence(resultSequence);
             }
             resultSequence.keepSingleton = true;


Test patch:
diff --git a/test/test-suite/groups/array-constructor/array-sequences.json b/test/test-suite/groups/array-constructor/array-sequences.json
new file mode 100644
index 0000000..4cb0e4d
--- /dev/null
+++ b/test/test-suite/groups/array-constructor/array-sequences.json
@@ -0,0 +1,68 @@
+[
+    {
+        "expr": "$.[value,epochSeconds][]",
+        "data": [
+            {
+                "epochSeconds": 1578381600,
+                "value": 3
+            },
+            {
+                "epochSeconds": 1578381700,
+                "value": 5
+            }
+        ],
+        "bindings": {},
+        "result": [
+            [3, 1578381600],
+            [5, 1578381700]
+        ]
+    },
+    {
+        "expr": "$.[value,epochSeconds][]",
+        "data": [
+            {
+                "epochSeconds": 1578381600,
+                "value": 3
+            }
+        ],
+        "bindings": {},
+        "result": [
+            [3, 1578381600]
+        ]
+    },
+    {
+        "expr": "$.[value,epochSeconds]",
+        "data": [
+            {
+                "epochSeconds": 1578381600,
+                "value": 3
+            }
+        ],
+        "bindings": {},
+        "result": [3, 1578381600]
+    },
+    {
+        "expr": "singleArray",
+        "data": {
+            "singleArray": [{"foo":"bar"}]
+        },
+        "bindings": {},
+        "result": [
+            {
+                "foo": "bar"
+            }
+        ]
+    },
+    {
+        "expr": "singleArray[]",
+        "data": {
+            "singleArray": [{"foo":"bar"}]
+        },
+        "bindings": {},
+        "result": [
+            {
+                "foo": "bar"
+            }
+        ]
+    }
+]