Skip to content

Commit 00f3ebe

Browse files
$eval() - array inputs should be wrapped
The logic for handling the second parameter to this function should be the same as for handling the input to any expression. This includes wrapping a top level array input in a singleton sequence so it gets treated as a single input. This code was missing from this function and is added here. Signed-off-by: andrew-coleman <andrew_coleman@uk.ibm.com>
1 parent 27724d9 commit 00f3ebe

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

src/jsonata.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1759,6 +1759,11 @@ var jsonata = (function() {
17591759
var input = this.input;
17601760
if(typeof focus !== 'undefined') {
17611761
input = focus;
1762+
// if the input is a JSON array, then wrap it in a singleton sequence so it gets treated as a single input
1763+
if(Array.isArray(input) && !isSequence(input)) {
1764+
input = createSequence(input);
1765+
input.outerWrapper = true;
1766+
}
17621767
}
17631768

17641769
try {
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
[
2+
{
3+
"expr": "$eval(\"{ 'test': 1 }\", [])",
4+
"data": {},
5+
"bindings": {},
6+
"result": {
7+
"test": 1
8+
}
9+
},
10+
{
11+
"expr": "$eval(\"{ 'test': 1 }\")",
12+
"data": [],
13+
"bindings": {},
14+
"result": {
15+
"test": 1
16+
}
17+
},
18+
{
19+
"expr": "$eval(\"{ 'test': 1 }\", [1,2,3])",
20+
"data": [],
21+
"bindings": {},
22+
"result": {
23+
"test": 1
24+
}
25+
},
26+
{
27+
"expr": "$eval(\"{ 'test': 1 }\")",
28+
"data": [1,2,3],
29+
"bindings": {},
30+
"result": {
31+
"test": 1
32+
}
33+
}
34+
]

0 commit comments

Comments
 (0)