Skip to content

Commit 65e854d

Browse files
authoredJan 6, 2022
Fixing reported issue #547 (#555)
* Fixing reported issue #547 * Fixing reported issue #547. Added unit test coverage. * Fixing reported issue #547. Added unit test coverage. * Fixing reported issue #547. Added unit test coverage. * Fixing reported issue #547. Added unit test coverage.
1 parent e6e436d commit 65e854d

File tree

2 files changed

+27
-18
lines changed

2 files changed

+27
-18
lines changed
 

‎src/jsonata.js

+21-18
Original file line numberDiff line numberDiff line change
@@ -922,32 +922,35 @@ var jsonata = (function() {
922922
var pair = expr.lhs[pairIndex];
923923
var key = yield * evaluate(pair[0], reduce ? item['@'] : item, env);
924924
// key has to be a string
925-
if (typeof key !== 'string') {
925+
if (typeof key !== 'string' && key !== undefined) {
926926
throw {
927927
code: "T1003",
928928
stack: (new Error()).stack,
929929
position: expr.position,
930930
value: key
931931
};
932932
}
933-
var entry = {data: item, exprIndex: pairIndex};
934-
if (groups.hasOwnProperty(key)) {
935-
// a value already exists in this slot
936-
if(groups[key].exprIndex !== pairIndex) {
937-
// this key has been generated by another expression in this group
938-
// when multiple key expressions evaluate to the same key, then error D1009 must be thrown
939-
throw {
940-
code: "D1009",
941-
stack: (new Error()).stack,
942-
position: expr.position,
943-
value: key
944-
};
945-
}
946933

947-
// append it as an array
948-
groups[key].data = fn.append(groups[key].data, item);
949-
} else {
950-
groups[key] = entry;
934+
if (key !== undefined) {
935+
var entry = {data: item, exprIndex: pairIndex};
936+
if (groups.hasOwnProperty(key)) {
937+
// a value already exists in this slot
938+
if(groups[key].exprIndex !== pairIndex) {
939+
// this key has been generated by another expression in this group
940+
// when multiple key expressions evaluate to the same key, then error D1009 must be thrown
941+
throw {
942+
code: "D1009",
943+
stack: (new Error()).stack,
944+
position: expr.position,
945+
value: key
946+
};
947+
}
948+
949+
// append it as an array
950+
groups[key].data = fn.append(groups[key].data, item);
951+
} else {
952+
groups[key] = entry;
953+
}
951954
}
952955
}
953956
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"expr": "$${id:{'label':label,'value':value}}",
3+
"data": [],
4+
"bindings": {},
5+
"result": {}
6+
}

0 commit comments

Comments
 (0)
Please sign in to comment.