# Suggestion to support JSONata in exec node

**URL:** <https://discourse.nodered.org/t/suggestion-to-support-jsonata-in-exec-node/42794>\
**Category:** Feature Requests\
**Created:** [18 March 2021 05:07 UTC](https://discourse.nodered.org/t/suggestion-to-support-jsonata-in-exec-node/42794 "2021-03-18T05:07:25Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![kazuhitoyokoi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kazuhitoyokoi/32/621_2.png) [@kazuhitoyokoi](https://discourse.nodered.org/u/kazuhitoyokoi)\
**Post date:** [18 March 2021 05:07 UTC](https://discourse.nodered.org/t/suggestion-to-support-jsonata-in-exec-node/42794/1 "2021-03-18T05:07:26Z")

</div>

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)

 ![currentflow](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/5/95ad8596b81aa46f507dc5e5895b88e375aa3ca6.png)

Flow

```auto
[{"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.

 ![execnode_jsonata](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/3/436fbead62a199da1973d6d8ef763d4efb45f4c0.png)

Image of exec node property with `typedInput`

 ![nodeproperty](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/9/59dc61071d12e5c7730523a21d9f3a8185176772.png)

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

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [18 March 2021 08:46 UTC](https://discourse.nodered.org/t/suggestion-to-support-jsonata-in-exec-node/42794/2 "2021-03-18T08:46:06Z")

</div>

Hi - most other nodes allow you to select the property that is used - eg  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/b/0b5de476b6057033575bdf318da06b2ad5399861.png)  
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 ?

---

<div class="post-metadata">

**Author:** ![kazuhitoyokoi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kazuhitoyokoi/32/621_2.png) [@kazuhitoyokoi](https://discourse.nodered.org/u/kazuhitoyokoi)\
**Post date:** [19 March 2021 10:41 UTC](https://discourse.nodered.org/t/suggestion-to-support-jsonata-in-exec-node/42794/3 "2021-03-19T10:41:15Z")

</div>

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.

 ![improved](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/6/46bc0ed4c761e2570ccdeda0cb2330a53466317b.png)

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.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [19 March 2021 11:42 UTC](https://discourse.nodered.org/t/suggestion-to-support-jsonata-in-exec-node/42794/4 "2021-03-19T11:42:26Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [19 March 2021 13:31 UTC](https://discourse.nodered.org/t/suggestion-to-support-jsonata-in-exec-node/42794/5 "2021-03-19T13:31:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [19 March 2021 13:40 UTC](https://discourse.nodered.org/t/suggestion-to-support-jsonata-in-exec-node/42794/6 "2021-03-19T13:40:28Z")

</div>

I was thinking more like

```auto
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.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [19 March 2021 13:46 UTC](https://discourse.nodered.org/t/suggestion-to-support-jsonata-in-exec-node/42794/7 "2021-03-19T13:46:29Z")

</div>

> [@dceejay](#):
>
> you haven't tried the 1.3-beta yet

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

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [19 March 2021 13:58 UTC](https://discourse.nodered.org/t/suggestion-to-support-jsonata-in-exec-node/42794/8 "2021-03-19T13:58:28Z")

</div>

> [@Colin](#):
>
> You are obviously telepathic

I already knew that...

---

<div class="post-metadata">

**Author:** ![kazuhitoyokoi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kazuhitoyokoi/32/621_2.png) [@kazuhitoyokoi](https://discourse.nodered.org/u/kazuhitoyokoi)\
**Post date:** [22 March 2021 07:46 UTC](https://discourse.nodered.org/t/suggestion-to-support-jsonata-in-exec-node/42794/9 "2021-03-22T07:46:20Z")

</div>

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!

> <https://github.com/node-red/node-red/pull/2908>

Image: (the `typedInput` has msg. only)

 ![execnode](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/4/e4290bbdb4fe58c5f8fdaca9b3c179d6a9da1d34.png)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [21 May 2021 07:46 UTC](https://discourse.nodered.org/t/suggestion-to-support-jsonata-in-exec-node/42794/10 "2021-05-21T07:46:22Z")

</div>

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