Ability to provide custom bindings to jsonata via settings.js

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 -

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 -

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

1 Like

No interest or comments from the maintainers?

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

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

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