Unexpected properties added to array result
See original GitHub issueWhen evaluating the expression payload[true][]
against { "payload": ["one"] }
the resulting array has some unexpected properties added to it: [ 'one', sequence: true, keepSingleton: true ]
.
var jsonata = require("jsonata");
var data = { payload: ["one"]}
var exp1 = jsonata("payload[true][]")
exp1.evaluate(data)
=> [ 'one', sequence: true, keepSingleton: true ]
This is the root cause of an issue raised against Node-RED: https://github.com/node-red/node-red/issues/2700 where the output of this expression was passed to another expression, and the result differed to when they passed what appeared to be the same payload straight to the second expression.
The Node-RED debug sidebar fails to display array properties, so they couldn’t see the difference in the messages - that’s a separate issue - but the expectation was the result would be the vanilla array without any extra properties on it.
Is that a reasonable expectation?
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:9 (5 by maintainers)
Here is a test case for the ‘second’ part of the issue.
In summary, if JSONata is given an array with a
sequence
property already set (data2
in the above example), then it treats it differently to one without that property set. This is specific to the property namedsequence
as it has special meaning in the internals of JSONata. (Note howdata3
is handled which has a property namedfoo
).I would suggest that if a fix for the original issue was found that removed the need to modify the array, then it would likely also mean it would no longer be looking for a
sequence
property and thus this issue would also get resolved with the same fix.@andrew-coleman here below the case for which I reported https://github.com/node-red/node-red/issues/2700