I have faced some unexpected behaviour when using jsonata in change node.
The following flow demonstrates the problem I am having.
Note that the actual flows I am using are using more complex jsonata expression but I believe that the essence of my problem is already demonstrated in this simple flow.
[{"id":"bfd23e84.79e77","type":"tab","label":"problem scenario","disabled":false,"info":""},{"id":"8424eb57.b8ac88","type":"inject","z":"bfd23e84.79e77","name":"msg.payload = [\"one\"]","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[\"one\"]","payloadType":"json","x":160,"y":340,"wires":[["2b87b72f.485d98","67db77ad.286958","3fc7f139.b687de"]]},{"id":"2b87b72f.485d98","type":"change","z":"bfd23e84.79e77","name":"(payload)[]","rules":[{"t":"set","p":"output","pt":"msg","to":"(payload)[]","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":690,"y":340,"wires":[["db08c8a7.2315a8"]]},{"id":"db08c8a7.2315a8","type":"debug","z":"bfd23e84.79e77","name":"output test 2 (OK)","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":930,"y":340,"wires":[]},{"id":"67db77ad.286958","type":"change","z":"bfd23e84.79e77","name":"payload[true][]","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload[true][]\t/* simple json expression retrieving all elements of array (condition is true)\t and assuring that the output is an array */","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":420,"y":300,"wires":[["ed307b32.12e1a8","278a2192.ee6bfe"]]},{"id":"ed307b32.12e1a8","type":"change","z":"bfd23e84.79e77","name":"(payload)[]","rules":[{"t":"set","p":"output","pt":"msg","to":"(payload)[]","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":690,"y":300,"wires":[["894cf205.51753"]]},{"id":"894cf205.51753","type":"debug","z":"bfd23e84.79e77","name":"output test 1 (NOT OK)","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":940,"y":300,"wires":[]},{"id":"278a2192.ee6bfe","type":"debug","z":"bfd23e84.79e77","name":"jsonata output","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":480,"y":260,"wires":[]},{"id":"3fc7f139.b687de","type":"debug","z":"bfd23e84.79e77","name":"test input","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":140,"y":280,"wires":[]}]
In the screenshot below you can see that the 2 nodes (payload)[]
(both are using exactly the same jsonata expression) are getting exactly the same payload as input according to the debug tab but the output is different. So it seems to indicate that the change node payload[true][]
is changing the payload in a way that is not visible in the debug tab.