Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing reported issue https://github.com/jsonata-js/jsonata/issues/547 #555

Merged
merged 5 commits into from
Jan 6, 2022
5 changes: 3 additions & 2 deletions src/jsonata.js
Original file line number Diff line number Diff line change
Expand Up @@ -922,14 +922,15 @@ var jsonata = (function() {
var pair = expr.lhs[pairIndex];
var key = yield * evaluate(pair[0], reduce ? item['@'] : item, env);
// key has to be a string
if (typeof key !== 'string') {
if (typeof key !== 'string' && key !== undefined) {
throw {
code: "T1003",
stack: (new Error()).stack,
position: expr.position,
value: key
};
}

var entry = {data: item, exprIndex: pairIndex};
if (groups.hasOwnProperty(key)) {
// a value already exists in this slot
Expand Down Expand Up @@ -964,7 +965,7 @@ var jsonata = (function() {
env = createFrameFromTuple(environment, tuple);
}
var value = yield * evaluate(expr.lhs[entry.exprIndex][1], context, env);
if(typeof value !== 'undefined') {
if(typeof value !== 'undefined' && key !== 'undefined') {
result[key] = value;
}
}
Expand Down
6 changes: 6 additions & 0 deletions test/test-suite/groups/object-constructor/case026.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"expr": "$${id:{'label':label,'value':value}}",
"data": [],
"bindings": {},
"result": {}
}