Skip to content

Commit 33bb565

Browse files
andrew-colemanmattbaileyuk
authored andcommittedAug 19, 2021
correctly handle empty array input to group expression
Signed-off-by: andrew-coleman <andrew_coleman@uk.ibm.com>
1 parent 57dba82 commit 33bb565

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed
 

‎src/jsonata.js

+4
Original file line numberDiff line numberDiff line change
@@ -910,6 +910,10 @@ var jsonata = (function() {
910910
if (!Array.isArray(input)) {
911911
input = createSequence(input);
912912
}
913+
// if the array is empty, add an undefined entry to enable literal JSON object to be generated
914+
if (input.length === 0) {
915+
input.push(undefined);
916+
}
913917

914918
for(var itemIndex = 0; itemIndex < input.length; itemIndex++) {
915919
var item = input[itemIndex];
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
[
2+
{
3+
"expr": "{'fgFoo:0:hausnummer': {'type': 'de.example.api.PossibleValuesList', 'value': [{'label': '', 'value': ''}] }}",
4+
"data": [],
5+
"result": {
6+
"fgFoo:0:hausnummer": {
7+
"type": "de.example.api.PossibleValuesList",
8+
"value": [{"label": "", "value": ""}]
9+
}
10+
}
11+
},
12+
{
13+
"expr": "{'fgFoo:0:hausnummer': {'type': 'de.example.api.PossibleValuesList', 'value': [{'label': '', 'value': ''}] }}",
14+
"data": [[]],
15+
"result": {
16+
"fgFoo:0:hausnummer": {
17+
"type": "de.example.api.PossibleValuesList",
18+
"value": [{"label": "", "value": ""}]
19+
}
20+
}
21+
},
22+
{
23+
"expr": "{'fgFoo:0:hausnummer': {'type': 'de.example.api.PossibleValuesList', 'value': [{'label': '', 'value': ''}] }}",
24+
"data": [[[]]],
25+
"result": {
26+
"fgFoo:0:hausnummer": {
27+
"type": "de.example.api.PossibleValuesList",
28+
"value": [{"label": "", "value": ""}]
29+
}
30+
}
31+
},
32+
{
33+
"expr": "{'fgFoo:0:hausnummer': {'type': 'de.example.api.PossibleValuesList', 'value': [{'label': '', 'value': ''}] }}",
34+
"data": {},
35+
"result": {
36+
"fgFoo:0:hausnummer": {
37+
"type": "de.example.api.PossibleValuesList",
38+
"value": [{"label": "", "value": ""}]
39+
}
40+
}
41+
}
42+
]

0 commit comments

Comments
 (0)
Please sign in to comment.