Skip to content

Commit ccb0109

Browse files
andrew-colemanmattbaileyuk
authored andcommitted
fix regression with singleton sequence of array type
Signed-off-by: andrew-coleman <andrew_coleman@uk.ibm.com>
1 parent 661e1d6 commit ccb0109

File tree

2 files changed

+70
-1
lines changed

2 files changed

+70
-1
lines changed

src/jsonata.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,8 @@ var jsonata = (function() {
219219
}
220220

221221
if(expr.keepSingletonArray) {
222-
if(!isSequence(resultSequence)) {
222+
// if the array is explicitly constructed in the expression and marked to promote singleton sequences to array
223+
if(Array.isArray(resultSequence) && resultSequence.cons && !resultSequence.sequence) {
223224
resultSequence = createSequence(resultSequence);
224225
}
225226
resultSequence.keepSingleton = true;
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
[
2+
{
3+
"expr": "$.[value,epochSeconds][]",
4+
"data": [
5+
{
6+
"epochSeconds": 1578381600,
7+
"value": 3
8+
},
9+
{
10+
"epochSeconds": 1578381700,
11+
"value": 5
12+
}
13+
],
14+
"bindings": {},
15+
"result": [
16+
[3, 1578381600],
17+
[5, 1578381700]
18+
]
19+
},
20+
{
21+
"expr": "$.[value,epochSeconds][]",
22+
"data": [
23+
{
24+
"epochSeconds": 1578381600,
25+
"value": 3
26+
}
27+
],
28+
"bindings": {},
29+
"result": [
30+
[3, 1578381600]
31+
]
32+
},
33+
{
34+
"expr": "$.[value,epochSeconds]",
35+
"data": [
36+
{
37+
"epochSeconds": 1578381600,
38+
"value": 3
39+
}
40+
],
41+
"bindings": {},
42+
"result": [3, 1578381600]
43+
},
44+
{
45+
"expr": "singleArray",
46+
"data": {
47+
"singleArray": [{"foo":"bar"}]
48+
},
49+
"bindings": {},
50+
"result": [
51+
{
52+
"foo": "bar"
53+
}
54+
]
55+
},
56+
{
57+
"expr": "singleArray[]",
58+
"data": {
59+
"singleArray": [{"foo":"bar"}]
60+
},
61+
"bindings": {},
62+
"result": [
63+
{
64+
"foo": "bar"
65+
}
66+
]
67+
}
68+
]

0 commit comments

Comments
 (0)