Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

Python bindings for JSONata.

Usage

from pyjsonata import jsonata

my_expression = "$"
my_json = "{'foo': 'bar'}"

# "{'foo': 'bar'}"
result = jsonata(my_expression, my_json)

With exception handling:

from pyjsonata import jsonata, PyjsonataError

my_expression = "$"
my_json = "{'foo': 'bar'}"

try:
    # "{'foo': 'bar'}"
    result = jsonata(my_expression, my_json)
except PyjsonataError as e:
    print("Error: ", e)

That’s it! Return values are always strings.

About

The reference implementation for JSONata is written in JavaScript. I have a separate library that makes this accessible from C via Duktape. This is a Python wrapper that calls into that library using Python’s built-in ctypes library, which should be portable to most Python interpreters.

At first I tried using py_mini_racer to run the JSONata library, but that package is around 40mb because it ships the complete V8 JavaScript runtime. In contrast this library is about 650k.

Building Packages

Source

Source packages are currently broken until I can be bothered to rewrite jsonata-c’s Makefile in Python, as required by setuptools.

🖕 setuptools.

Wheels

pyjsonata can be built to the manylinux2014 standard. There is no Windows support at this time.

The standard way to build manylinux2014 compatible extensions is with a bunch of Centos 7 Docker containers. The idea is that by linking against Centos 7 libc, the resultant binaries will be “portable enough” to modern systems. You don’t have to use these, but it’s not a bad idea.

Without Docker

  • Install gcc, patchelf and make from your distro repository

  • Install Python build deps:

    python3 -m pip install setuptools wheel auditwheel

To build:

git submodule update --init --recursive
python3 -m setup.py bdist_wheel
cd dist && auditwheel repair ./*.whl
mv wheelhouse/*.whl .

This will make you manylinux2014 wheels. These wheels are tagged to your specific Python version and ABI, like cp37-cp37m, but in reality, they should be py3-none. I can’t figure out how to make setuptools understand that. I think you can safely manually re-tag these by unzipping the wheel, editing the metadata in the WHEEL file, rezipping it, and changing the tag in the filename, but I haven’t yet tested whether that yields the desired results.

However, the arch tag, e.g. x86_64, aarch64, armv7l etc, is necessary.

With Docker

./build.sh <arch>

arch must be one of the architectures for which manylinux2014 build containers are provided. For example, if you are building on aarch64:

./build.sh aarch64

This will download the appropriate container and run the build. Built wheels are in the dist directory.

If you are me:

python3 -m twine upload --repository-url https://upload.pypi.org/legacy/ dist/*manylinux2014_*.whl

Testing

Pytest

From the repository root:

python3 -m pip install pytest
python3 -m pytest

Release files for pyjsonata 0.0.1a10

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for pyjsonata 0.0.1a10
File
pyjsonata-0.0.1a10-cp39-cp39-manylinux2014_x86_64.whl CPython 3.9 CPython 3.9 Linux glibc 2.17+ x86-64 Details
pyjsonata-0.0.1a10-cp38-cp38-manylinux2014_x86_64.whl CPython 3.8 CPython 3.8 Linux glibc 2.17+ x86-64 Details
pyjsonata-0.0.1a10-cp37-cp37m-manylinux2014_x86_64.whl CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.17+ x86-64 Details
pyjsonata-0.0.1a10-cp36-cp36m-manylinux2014_x86_64.whl CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.17+ x86-64 Details
pyjsonata-0.0.1a10-cp35-cp35m-manylinux2014_x86_64.whl CPython 3.5 CPython 3.5 pymalloc Linux glibc 2.17+ x86-64 Details

Total release size: 1.4 MB

Release files / pyjsonata-0.0.1a10-cp39-cp39-manylinux2014_x86_64.whl

Download URL pyjsonata-0.0.1a10-cp39-cp39-manylinux2014_x86_64.whl
Size 285.0 kB
Tags CPython 3.9 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
24f87e13d7e87f0d72798061f5888f1c928190cdc6a4fe43e5b467aefe09542b
BLAKE2b-256 checksum
How to use checksums
64fb9978597de662cf70348beb104754e09e3b08ccbf5bcbc653862aaeb3c4e5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.9

Release files / pyjsonata-0.0.1a10-cp38-cp38-manylinux2014_x86_64.whl

Download URL pyjsonata-0.0.1a10-cp38-cp38-manylinux2014_x86_64.whl
Size 285.0 kB
Tags CPython 3.8 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
1f11d7c08cc128c6e150f464b731787d39dfad009ce06914b44c386db724a734
BLAKE2b-256 checksum
How to use checksums
623d09f9561357f328bce76ddeba5dd100e82c4af9041993846bd0b1ab31cfdc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.9

Release files / pyjsonata-0.0.1a10-cp37-cp37m-manylinux2014_x86_64.whl

Download URL pyjsonata-0.0.1a10-cp37-cp37m-manylinux2014_x86_64.whl
Size 285.0 kB
Tags CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
7ec6c0f391827a647663d6003ba3e5abc25f97f95f3a7fa29bdbf6830e705dfe
BLAKE2b-256 checksum
How to use checksums
7aa96d37247ea0d542f2f7c3307b045feeeb3e224b650e39aed66c84fb965c7f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.9

Release files / pyjsonata-0.0.1a10-cp36-cp36m-manylinux2014_x86_64.whl

Download URL pyjsonata-0.0.1a10-cp36-cp36m-manylinux2014_x86_64.whl
Size 285.0 kB
Tags CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
c1803c3083afbbc4aab87b08922564353f5422e9fbd2d99302df792300d0052e
BLAKE2b-256 checksum
How to use checksums
e843612182789f49849942d9cf54c678baad4f997a624643161a0b44010dfd94
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.9

Release files / pyjsonata-0.0.1a10-cp35-cp35m-manylinux2014_x86_64.whl

Download URL pyjsonata-0.0.1a10-cp35-cp35m-manylinux2014_x86_64.whl
Size 285.0 kB
Tags CPython 3.5 CPython 3.5 pymalloc Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
bcbfa888bd139aaef5c47e19725fa0342fa60ef13eab1fd7a8c3491f702eaef3
BLAKE2b-256 checksum
How to use checksums
453c5a36cf825d3be28b8c56801602a68033cfdc94c915edf280a56899db2655
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.9
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page