Pure Python implementation of JSONata
Actively maintained. Last release 2 weeks ago, commits in 9 of the last 26 weeks. A safe choice.
pip install jsonata-pythonjsonata-python
Pure Python implementation of JSONata.
This is a Python port of the JSONata reference implementation, and also borrows from the Dashjoin Java port.
This implementation supports 100% of the language features of JSONata, with no external dependencies. The JSONata documentation can be found here.
Installation
pipx install jsonata-python
Getting Started
A very simple start:
>>> import jsonata
>>> data = {"example": [{"value": 4}, {"value": 7}, {"value": 13}]}
>>> expr = jsonata.Jsonata("$sum(example.value)")
>>> result = expr.evaluate(data)
>>> result
24
Command Line Interface
The CLI provides the same functionality as the Dashjoin JSONata CLI.
% jsonata -h
usage: jsonata [-h] [-v] [-e <file>] [-i <arg>] [-ic <arg>] [-f {auto,json,string}] [-o <arg>] [-oc <arg>] [-time] [-c] [-b <json-string>]
[-bf <file>] [-it]
[expr]
Pure Python JSONata CLI
positional arguments:
expr
options:
-h, --help show this help message and exit
-v, --version show program's version number and exit
-e <file>, --expression <file>
JSON expression to evaluate.
-i <arg>, --input <arg>
JSON input file (- for stdin)
-ic <arg>, --icharset <arg>
Input character set (default=utf-8)
-f {auto,json,string}, --format {auto,json,string}
Input format (default=auto)
-o <arg>, --output <arg>
JSON output file (default=stdout)
-oc <arg>, --ocharset <arg>
Output character set (default=utf-8)
-time Print performance timers to stderr
-c, --compact Compact JSON output (don't prettify)
-b <json-string>, --bindings <json-string>
JSONata variable bindings
-bf <file>, --bindings-file <file>
JSONata variable bindings file
-it, --interactive Interactive REPL (requires input file)