Suggestion to support JSONata in exec node

In Node-RED events and documents, I often see the many pairs of change node (or function node) and exec node. Because the current exec node supports just msg.payload to specify a value in the received message. To solve the situation, I would like to suggest that the exec node supports JSONata as typedInput in the command field.

Current exec node
The following flow is an example that uses pair of the change node and exec node. (Yellow file node is node-red-contrib-browser-utils module to upload file from the browser)


[{"id":"c55b3f36.bc62c","type":"http response","z":"6d621a26.d5de24","name":"","statusCode":"","headers":{},"x":630,"y":200,"wires":[]},{"id":"f0087c1c.badd","type":"file","z":"6d621a26.d5de24","name":"save data to file","filename":"","appendNewline":true,"createDir":true,"overwriteFile":"true","encoding":"none","x":600,"y":100,"wires":[["f7fdb56e.f87f68"]]},{"id":"31494145.0706ae","type":"change","z":"6d621a26.d5de24","name":"msg.payload = <file buffer>\\n msg.filename = 'tmp/<timestamp>.jpg'","rules":[{"t":"set","p":"payload","pt":"msg","to":"req.files[0].buffer","tot":"msg"},{"t":"set","p":"filename","pt":"msg","to":"'tmp/' & $millis() & '.jpg'","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":350,"y":100,"wires":[["f0087c1c.badd"]]},{"id":"7a1eb15.26b465","type":"http in","z":"6d621a26.d5de24","name":"","url":"/fileupload","method":"post","upload":true,"swaggerDoc":"","x":100,"y":100,"wires":[["31494145.0706ae"]]},{"id":"ba523599.4f7898","type":"comment","z":"6d621a26.d5de24","name":"REST API to upload file and handle it using command","info":"","x":220,"y":40,"wires":[]},{"id":"f045dfa1.b84db","type":"comment","z":"6d621a26.d5de24","name":"File upload flow","info":"","x":100,"y":300,"wires":[]},{"id":"c8afa05c.3ecaa","type":"http request","z":"6d621a26.d5de24","name":"file upload","method":"POST","ret":"txt","paytoqs":"ignore","url":"http://localhost:1880/fileupload","tls":"","persist":false,"proxy":"","authType":"","x":430,"y":340,"wires":[["2377f84a.cc7258"]]},{"id":"2377f84a.cc7258","type":"debug","z":"6d621a26.d5de24","name":"ouput md5 value","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":610,"y":340,"wires":[]},{"id":"b4af66bf.39e728","type":"fileinject","z":"6d621a26.d5de24","name":"","x":100,"y":340,"wires":[["9ea60a13.5f1838"]]},{"id":"9ea60a13.5f1838","type":"function","z":"6d621a26.d5de24","name":"create post data","func":"msg.headers = { 'Content-Type': 'multipart/form-data' };\nmsg.payload = {\n    'file' : {\n        'value': msg.payload,\n        'options': { 'filename': 'file.jpg' }\n    }\n};\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":260,"y":340,"wires":[["c8afa05c.3ecaa"]]},{"id":"c67f51a3.b3467","type":"group","z":"6d621a26.d5de24","name":"Pair of change and exec node","style":{"stroke":"#ff0000","label":true,"label-position":"s","color":"#ff0000"},"nodes":["250e2ea0.fad9e2","f7fdb56e.f87f68"],"x":34,"y":151.5,"w":532,"h":105},{"id":"250e2ea0.fad9e2","type":"exec","z":"6d621a26.d5de24","g":"c67f51a3.b3467","command":"md5sum","addpay":true,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"md5sum + msg.payload","x":430,"y":200,"wires":[["c55b3f36.bc62c"],[],[]]},{"id":"f7fdb56e.f87f68","type":"change","z":"6d621a26.d5de24","g":"c67f51a3.b3467","name":"msg.payload = msg.filename","rules":[{"t":"set","p":"payload","pt":"msg","to":"filename","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":180,"y":200,"wires":[["250e2ea0.fad9e2"]]}]

exec node using JSONata
If the exec node supports JSONata, the flow doesn't need to have a change node to set msg.payload before exec node.

Image of exec node property with typedInput

Additionally, users can specify more than two variables using JSONata in the exec node.

Hi - most other nodes allow you to select the property that is used - eg
Would it not be more in line with other nodes behaviour to make this the same - so change the append checkbox line to allow this choice of property ?


Thank you for your advice. I agree with your idea of the append field. I pasted the image to support the typedInput in the field.

I found that it is also suitable for other choices like environment variables and "msg.". I think that it may be better not to change the "msg.payload" check box because of flow compatibility.

1 Like

If this change is made can I suggest that the default for whether to append the selected property to the command is changed to disabled. We regularly get issues here with users who have accidentally left it selected. This would only affect new exec nodes not existing ones already deployed of course.

@colin - obviously you haven't tried the 1.3-beta yet :wink:

I was thinking more like

Append       [  ]   [msg.] payload

so it is visually consistent with what we have.
with the default being msg.payload of course - and not really needing the string option as that can be handled by the existing extra parameters input which I think we still need. I'm no really convinced we need jsonata in there either. Indeed I would prefer it was just msg. as that is then consistent with other nodes. We deliberately use the change node for moving things in and out for flow and global context.

Actually I have, but I didn't check the setting on that system :slight_smile:
You are obviously telepathic, adding features before we even get round to asking for them.

1 Like

I already knew that...


Thank you for the discussion. I submitted the pull request to use the typedInput in msg.payload without JSONata. It is simple and fills our requirements!

Image: (the typedInput has msg. only)


This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.