Skip to content

Bindings error in expression.evaluate() method #16

Closed

Description

@tokebe

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

Activity

  1. rayokota commented on Mar 15, 2025

    @rayokota
    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"
    
  2. tokebe commented on Mar 17, 2025

    @tokebe
    Author

    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...

  3. rayokota commented on Mar 20, 2025

    @rayokota
    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

  4. TheCaffinatedDeveloper commented on Aug 27, 2025

    @TheCaffinatedDeveloper

    @rayokota Can we confirm this works as expected for lambda functions? Trying to do this
    https://github.com/dashjoin/jsonata-java/blob/main/src/test/java/com/dashjoin/jsonata/CustomFunctionTest.java
    But having an issue replicating

  5. rayokota commented on Jul 5, 2026

    @rayokota
    Owner

    Fixed by #39

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions