# \[Feature Request\]Allow one-liner JavaScript as well as JSONata

**URL:** <https://discourse.nodered.org/t/feature-request-allow-one-liner-javascript-as-well-as-jsonata/82825>\
**Category:** Feature Requests\
**Created:** [13 November 2023 11:47 UTC](https://discourse.nodered.org/t/feature-request-allow-one-liner-javascript-as-well-as-jsonata/82825 "2023-11-13T11:47:51Z")\
**Posts on this page:** 8\
**Page:** 3

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [14 November 2023 23:23 UTC](https://discourse.nodered.org/t/feature-request-allow-one-liner-javascript-as-well-as-jsonata/82825/41 "2023-11-14T23:23:57Z")

</div>

> [@TotallyInformation](#):
>
> Oh, and of course, it returns an actual number not text.

Sure if you use the wrong function.

```auto
$floor($random() * 100)

```

---

<div class="post-metadata">

**Author:** ![kuema](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kuema/32/6542_2.png) [@kuema](https://discourse.nodered.org/u/kuema)\
**Post date:** [15 November 2023 07:46 UTC](https://discourse.nodered.org/t/feature-request-allow-one-liner-javascript-as-well-as-jsonata/82825/42 "2023-11-15T07:46:10Z")

</div>

To be honest... while I see the benefits and flexibility about this feature, I'd be careful.

It is just _yet another way_ of doing something, that could already be achieved by using the `function` node.  
Once people start putting more than a one-liner in there, things get messy and unmaintainable, can have unclear side-effects, etc...

Simply allowing for complex expressions in a single field of a `change` node kind of defeats the benefits of Node-RED as a **visual** programming tool. Simply put: The presence of a `function` node makes that fact visually clear to me, I know, there's a piece of (complex) Javascript in there. On the other hand, a single field in a `change` node doesn't.

A tale from my own experience (a long time before Node-RED): I once integrated a simple expression language into a Java application to allow some user flexibility without the need to touch the code every time. The "creativity" of my colleagues for misusing such things was (and is) endless in that regard, once you gave them the necessary means. You couldn't imagine the (evil) things they created with it... 🙈

Just my _gut feeling_ about this... 😅

---

<div class="post-metadata">

**Author:** ![ralphwetzel](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ralphwetzel/32/53713_2.png) [@ralphwetzel](https://discourse.nodered.org/u/ralphwetzel)\
**Post date:** [15 November 2023 08:41 UTC](https://discourse.nodered.org/t/feature-request-allow-one-liner-javascript-as-well-as-jsonata/82825/43 "2023-11-15T08:41:28Z")

</div>

> [@kuema](#):
>
> You couldn't imagine the (evil) things they created with it...

That's human creativity in action! 😁

Leaving off any bias, this leads to the story of the knifes. People have to learn which end hurts - either by being teached (not just told!) or by personal experience. Yet as we all know, despite this latent danger, we're still using knives - and are occasionally extremely proud when they are laser sharp.

Additionally - e.g. if you're in a production environment - there's always the option to switch off this feature. Alternatively, it might be an idea to `opt in` this functionality - as it's already the case with a number of others.

> [@kuema](#):
>
> Simply allowing for complex expressions in a single field of a `change` node kind of defeats the benefits of Node-RED as a **visual** programming tool.

Agreed. Still it might be an efficient way to do things - and it's [already done](https://discourse.nodered.org/t/can-any-one-help-with-a-more-elegant-way-of-me-extracting-the-data-i-need-from-a-json-string/82335/11):

> [@Can any one help with a more elegant way of me extracting the data I need from a JSON string](https://discourse.nodered.org/t/can-any-one-help-with-a-more-elegant-way-of-me-extracting-the-data-i-need-from-a-json-string/82335/11):
>
> I prefer to use this JSONata expression:
> 
> ```auto
> payload {
> cid: $ ~> | $ | 
> data {
> "timestamp": $fromMillis($number($keys($)[0])),
> "data": *
> }
> |
> }
> 
> ```
> 
> (although most "normal" people would opt for plain JS ;\*)

BTW, this shows up in the editor as

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/3/d3172ced0bf29b3e87f5509201bd5872f0431fe3.png)

🤔

---

<div class="post-metadata">

**Author:** ![kuema](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kuema/32/6542_2.png) [@kuema](https://discourse.nodered.org/u/kuema)\
**Post date:** [15 November 2023 08:57 UTC](https://discourse.nodered.org/t/feature-request-allow-one-liner-javascript-as-well-as-jsonata/82825/44 "2023-11-15T08:57:15Z")

</div>

To quote Scotty from Star Trek: _"How many times da I have to tell ya...the right tool for the right job!"_ 🤓

I should add, I'm not a big fan JSONata either. Yes, it's powerful for accessing/transforming your data, but complex and time consuming if you don't use it regularly. So the function node using plain JS is my go-to tool in these cases.  
And it faces the same issue regarding one-liners vs. complex expressions. Not ideal for creating maintainable and comprehensible flows. 😅

---

<div class="post-metadata">

**Author:** ![gemini86](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gemini86/32/70967_2.png) [@gemini86](https://discourse.nodered.org/u/gemini86)\
**Post date:** [15 November 2023 15:35 UTC](https://discourse.nodered.org/t/feature-request-allow-one-liner-javascript-as-well-as-jsonata/82825/45 "2023-11-15T15:35:01Z")

</div>

I'm seeing a lot of interesting ideas here, as well as some that are definitely not "node-red" style compatible. Plenty of things being suggested could be done with existing nodes/subflow/link nodes and be just as, if not _more_ tidy. I would, however, really like to be able to use object prototypes from the change node. setting msg.payload to msg.payload.toUpperCase() is a great example. I know this can be done in a template node, but if you're doing a small chain of changes to one property, doing it in one change node is nice. My $0.04 (accounting for inflation)

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [15 November 2023 18:52 UTC](https://discourse.nodered.org/t/feature-request-allow-one-liner-javascript-as-well-as-jsonata/82825/46 "2023-11-15T18:52:07Z")

</div>

Been thinking about things and now agree with @TotallyInformation that good idea to have this in inject as well as switch and change nodes

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [15 November 2023 19:06 UTC](https://discourse.nodered.org/t/feature-request-allow-one-liner-javascript-as-well-as-jsonata/82825/47 "2023-11-15T19:06:00Z")

</div>

If it makes it into the typed input as a standard piece like JSONata, then it should become available everywhere that uses typed input with a simple change to add the new type to the list of available ones.

So the main thing is to get it into core, updates to nodes - while nice to have all the core ones updated together - don't all need to happen at once if resources aren't free to make the changes.

---

<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:** [14 January 2024 19:06 UTC](https://discourse.nodered.org/t/feature-request-allow-one-liner-javascript-as-well-as-jsonata/82825/48 "2024-01-14T19:06:58Z")

</div>

Closed on 14 January 2024 19:06 UTC

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

[Previous page](https://discourse.nodered.org/t/feature-request-allow-one-liner-javascript-as-well-as-jsonata/82825.md?page=2)
