JSONata for Python — Rust port of the jsonata-java reference implementation
Actively maintained. Last release 5 months ago. A safe choice.
pip install jsonata-rsjsonata-rs
Python bindings for the Rust port of jsonata-java.
- PyPI distribution name:
jsonata-rs—pip install jsonata-rs - Import name:
jsonata—import jsonata - Requires Python ≥ 3.11; published as a single
abi3wheel per platform (Linux amd64 + arm64, macOS arm64).
import jsonata
expr = jsonata.Jsonata("Account.Order.Product.(Price * Quantity) ~> $sum()")
expr.evaluate(data) # evaluate against a dict / list / scalar
# variable bindings
jsonata.Jsonata("$x + 1").evaluate(None, {"x": 41}) # -> 42
# one-shot convenience
jsonata.evaluate("a + b", {"a": 2, "b": 3}) # -> 5
# custom functions written in Python
e = jsonata.Jsonata("$greet(name)")
e.register_function("greet", lambda n: f"Hello, {n}!")
e.evaluate({"name": "World"}) # -> "Hello, World!"
Errors raise jsonata.JsonataError with .code (e.g. "S0201") and .position.
An internal engine bug (a caught Rust panic) raises jsonata.JsonataInternalError
— a subclass of JsonataError, so existing handlers still catch it — with
.code == "PANIC" and a .panic_location.
try:
result = jsonata.Jsonata(expr).evaluate(data)
except jsonata.JsonataError as e:
print(e.code, e.position) # e.g. "S0201" 4
Type checking
The package ships PEP 561 type information (a jsonata.pyi stub plus a
py.typed marker), so mypy and pyright type the full public API out of the box —
including JsonataError.code: str, .position: int, and
JsonataInternalError.panic_location: str | None. No stub package to install.
Value mapping
| JSONata | Python |
|---|---|
| number | int (whole) / float |
| string | str |
| boolean | bool |
| null | None |
| undefined |