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

Bindings error in expression.evaluate() method #16

Closed
tokebe opened this issue Mar 14, 2025 · 3 comments
Closed

Bindings error in expression.evaluate() method #16

tokebe opened this issue Mar 14, 2025 · 3 comments

Comments

@tokebe
Copy link

tokebe commented Mar 14, 2025

Thanks for writing this package! It shocks me that jsonata isn't more popular.

Bindings appear to be broken in the evaluate method, minimal example:

import jsonata
expr = jsonata.Jsonata("$ & $test_value")
expr.evaluate("a string!", {"test_value": "test"})

Produces error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/jcallaghan/.pyenv/versions/3.11.10/lib/python3.11/site-packages/jsonata/jsonata.py", line 1947, in evaluate
    for k, v in bindings.bindings.items():
                ^^^^^^^^^^^^^^^^^
AttributeError: 'dict' object has no attribute 'bindings'

However, expression.assign() still seems to work:

import jsonata
expr = jsonata.Jsonata("$ & $test_value")
expr.assign("test_value", "test")
print(expr.evaluate("a string!"))

Outputs as expected:

a string!test
@rayokota
Copy link
Owner

The bindings parameter needs to an instance of Jsonata.Frame. The following works

        expr = jsonata.Jsonata("$ & $test_value")
        frame = jsonata.Jsonata.Frame(None)
        frame.bind("test_value", "test")
        expr.evaluate("a string!", frame) == "a string!test"

@tokebe
Copy link
Author

tokebe commented Mar 17, 2025

This goes against the reference implementation documentation. Is this an intentional departure from being a strict port of the reference implementation?

I'd be happy to make a PR...

@rayokota
Copy link
Owner

Right, this port is more closely aligned with the Java implementation. See https://github.com/dashjoin/jsonata-java?tab=readme-ov-file#custom-functions

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

No branches or pull requests

2 participants