# Ability to provide custom bindings to jsonata via settings.js

**URL:** <https://discourse.nodered.org/t/ability-to-provide-custom-bindings-to-jsonata-via-settings-js/52032>\
**Category:** Feature Requests\
**Created:** [9 October 2021 07:20 UTC](https://discourse.nodered.org/t/ability-to-provide-custom-bindings-to-jsonata-via-settings-js/52032 "2021-10-09T07:20:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mannharleen](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mannharleen/32/25594_2.png) [@mannharleen](https://discourse.nodered.org/u/mannharleen)\
**Post date:** [9 October 2021 07:20 UTC](https://discourse.nodered.org/t/ability-to-provide-custom-bindings-to-jsonata-via-settings-js/52032/1 "2021-10-09T07:20:46Z")

</div>

The jsonata within NR already has some bindings defined by NR that allow access to flowContext etc.  
Now, in my belief to empower\* the NR users and encourage the use of jsonata, we need the ability to create custom bindings to the jsonata evaluation.

- as an example, the admin could enable a DB connection as a binding and provide a `$sql(...)` function that can be used within jsonata expressions.

I believe the ideal place will be settings.js.  
Comments? Thoughts?

* * *

Edit 1  
Just out of curiosity; if you need inspiration or a workaround for now, this is how one can create custom bindings using function node -

```js
let data = msg
let bindings = {
    // provide binding to access global context as `$global.get("key")`
    global: {
        get: (k) => {
            return global.get(k)
        }
    }
}
let jexp = RED.util.prepareJSONataExpression('$global.get("env")', node)
msg.payload = jexp.evaluate(data, bindings)
return msg;

```

* * *

Edit 2  
If this feature request is accepted, the additional bindings would need to be added here -

> <https://github.com/node-red/node-red/blob/bb8d7058a49a41047f953e7ce83562b4a7f44cc4/packages/node_modules/%40node-red/util/lib/util.js#L662>

> PS\> I am happy to create a PR, but need to discuss this through first

---

<div class="post-metadata">

**Author:** ![mannharleen](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mannharleen/32/25594_2.png) [@mannharleen](https://discourse.nodered.org/u/mannharleen)\
**Post date:** [24 October 2021 08:53 UTC](https://discourse.nodered.org/t/ability-to-provide-custom-bindings-to-jsonata-via-settings-js/52032/2 "2021-10-24T08:53:37Z")

</div>

No interest or comments from the maintainers?

---

<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:** [24 October 2021 08:55 UTC](https://discourse.nodered.org/t/ability-to-provide-custom-bindings-to-jsonata-via-settings-js/52032/3 "2021-10-24T08:55:34Z")

</div>

Been slightly busy getting 2.1 out the door if you hadn’t noticed.

---

<div class="post-metadata">

**Author:** ![mannharleen](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mannharleen/32/25594_2.png) [@mannharleen](https://discourse.nodered.org/u/mannharleen)\
**Post date:** [24 October 2021 09:07 UTC](https://discourse.nodered.org/t/ability-to-provide-custom-bindings-to-jsonata-via-settings-js/52032/4 "2021-10-24T09:07:34Z")

</div>

Yes of course. Didn’t mean it like that.

---

<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:** [23 December 2021 09:08 UTC](https://discourse.nodered.org/t/ability-to-provide-custom-bindings-to-jsonata-via-settings-js/52032/5 "2021-12-23T09:08:15Z")

</div>

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