Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: How To Evaluate A JSONata Function In A User-Defined Function? #259

Closed
goulderb opened this issue Oct 1, 2018 · 1 comment · Fixed by #279
Closed

Question: How To Evaluate A JSONata Function In A User-Defined Function? #259

goulderb opened this issue Oct 1, 2018 · 1 comment · Fixed by #279

Comments

@goulderb
Copy link

goulderb commented Oct 1, 2018

Hello,

Is it possible to implement a user-defined function in JavaScript that could be bound in using .registerFunction/.assign/bindings, and take in an arbitrary JSONata function? Right now, all that I receive is an object that I do not know how to evaluate against other data that is provided to the function.

For example, say I have a scenario like the following:

import jsonata from 'jsonata';

const exampleFn = (value, fn) => { ... };

const expression = jsonata('$exampleFn(["test", "test2"], function ($v) { $v })');
const transformedData = expression.evaluate({}, { exampleFn });

Ignoring what exampleFn does, the JSONata function that gets passed is sent in as an object. This object doesn't seem to have any direct way to evaluate it and run it. This essentially makes it impossible to bind through higher order functions to JSONata, which would be a great help to me as I have been adding on functions that require native JavaScript implementations for performance reasons.

This would also help to make it easier to implement extensions on top of JSONata, similar to what was proposed on #117.

@andrew-coleman
Copy link
Member

Thanks for raising this. It would be useful if fn in your example was passed into your extension function as a javascript function that could be invoked directly. I'll see what we can do here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants