diff --git a/src/jsonata.js b/src/jsonata.js index aa40ccf4..bfc8db99 100644 --- a/src/jsonata.js +++ b/src/jsonata.js @@ -1759,6 +1759,11 @@ var jsonata = (function() { var input = this.input; if(typeof focus !== 'undefined') { input = focus; + // if the input is a JSON array, then wrap it in a singleton sequence so it gets treated as a single input + if(Array.isArray(input) && !isSequence(input)) { + input = createSequence(input); + input.outerWrapper = true; + } } try { diff --git a/test/test-suite/groups/function-eval/case008.json b/test/test-suite/groups/function-eval/case008.json new file mode 100644 index 00000000..e22d718e --- /dev/null +++ b/test/test-suite/groups/function-eval/case008.json @@ -0,0 +1,34 @@ +[ + { + "expr": "$eval(\"{ 'test': 1 }\", [])", + "data": {}, + "bindings": {}, + "result": { + "test": 1 + } + }, + { + "expr": "$eval(\"{ 'test': 1 }\")", + "data": [], + "bindings": {}, + "result": { + "test": 1 + } + }, + { + "expr": "$eval(\"{ 'test': 1 }\", [1,2,3])", + "data": [], + "bindings": {}, + "result": { + "test": 1 + } + }, + { + "expr": "$eval(\"{ 'test': 1 }\")", + "data": [1,2,3], + "bindings": {}, + "result": { + "test": 1 + } + } +]