Skip to content

Commit 43724dc

Browse files
keepArray syntax should apply to all expression types
1 parent 42ad469 commit 43724dc

File tree

4 files changed

+21
-0
lines changed

4 files changed

+21
-0
lines changed

src/jsonata.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1410,6 +1410,9 @@ var jsonata = (function() {
14101410
throw err;
14111411
}
14121412
}
1413+
if(expr.keepArray) {
1414+
result.keepArray = true;
1415+
}
14131416
return result;
14141417
};
14151418

@@ -1594,6 +1597,9 @@ var jsonata = (function() {
15941597
}
15951598

15961599
if(result && result.sequence) {
1600+
if(expr.keepArray) {
1601+
result.keepSingleton = true;
1602+
}
15971603
result = result.value();
15981604
}
15991605

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"expr": "$[type='command'][]",
3+
"data": [{"type":"command"},{"type":"commands"}],
4+
"result": [{"type":"command"}]
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"expr": "$[][type='command']",
3+
"data": [{"type":"command"},{"type":"commands"}],
4+
"result": [{"type":"command"}]
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"expr": "$filter($, function($e) { $e != 0 })[]",
3+
"data": [0,0,5,0],
4+
"result": [5]
5+
}

0 commit comments

Comments
 (0)