Right now, binding variables requires a bit of investigation into the internals:
from jsonata import Jsonata as JS
data = {
"products": [
{"name": "Apple", "price": 1.20},
{"name": "Banana", "price": 0.50},
{"name": "Cherry", "price": 2.50}
]
}
# It would be nice to be able to just input this dictionary.
bindings = {
"maxPrice": 1.50,
"currencySymbol": "$"
}
# Instead we have to create an empty Frame object and bind each item.
binding_frame = JS.Frame(None)
for k, v in input.items():
binding_frame.bind(k, v)
expression = jsonata.Jsonata("products[price <= $maxPrice].(name & ' costs ' & $currencySymbol & $string(price))")
result = expression.evaluate(data, bindings=binding_frame)
print(result)
# ['Apple costs $1.2', 'Banana costs $0.5']
It would be nice to simply be able to pass a dictionary as the bindings parameter to evaluate().
Right now, binding variables requires a bit of investigation into the internals:
It would be nice to simply be able to pass a dictionary as the
bindingsparameter toevaluate().