JSONata for Python
jsonata-python is a pure Python implementation of the JSONata query and transformation language, currently at version 0.6.2. It aims to provide 100% of the language features of JSONata without external dependencies, offering a performant alternative to Python libraries that rely on JavaScript bindings. The library maintains a steady release cadence with updates reflecting the upstream JSONata specification.
Warnings
- gotcha JSONata date/time functions that utilize ISO 8601 formats are only fully supported when running on Python 3.11 or newer. Users on older Python versions (3.10 and below) may experience issues or limited functionality with these specific date/time operations.
- gotcha This 'jsonata-python' library is a pure Python implementation. Older Python wrappers for JSONata, such as 'jsonata-wrapper' or 'pyjsonata', often relied on JavaScript bindings and may have different APIs, performance characteristics, and potential compatibility issues. Ensure you are importing from 'jsonata' if you intend to use this pure Python version.
Install
-
pip install jsonata-python -
pipx install jsonata-python
Imports
- Jsonata
import jsonata expr = jsonata.Jsonata(...)
Quickstart
import jsonata
data = {"example": [{"value": 4}, {"value": 7}, {"value": 13}]}
expr_str = "$sum(example.value)"
expr = jsonata.Jsonata(expr_str)
result = expr.evaluate(data)
print(f"JSONata expression: {expr_str}")
print(f"Input data: {data}")
print(f"Result: {result}")