Skip to main content

JsonLogic implemented with a Rust backend

Project description

json-logic-rs

Continuous Integration

This is an implementation of the JsonLogic specification in Rust.

Project Status

We implement 100% of the standard supported operations defined here.

We also implement the ?:, which is not described in that specification but is a direct alias for if.

All operations are tested using our own test suite in Rust as well as the shared tests for all JsonLogic implementations defined here.

We are working on adding new operations with improved type safety, as well as the ability to define functions as JsonLogic. We will communicate with the broader JsonLogic community to see if we can make them part of the standard as we do so.

Being built in Rust, we are able to provide the package in a variety of languages. The table below describes current language support:

Language Available Via
Rust Cargo
JavaScript (as WASM) Node Package via NPM
Python PyPI

Installation

Rust

Just add to your Cargo.toml:

[dependencies]
jsonlogic-rs = "~0.1.1"

Node/Browser

You can install JsonLogic using npm or yarn. In NPM:

npm install --save @bestow/jsonlogic-rs

Note that the package is distributed as a node package, so you'll need to use browserify, webpack, or similar to install for the browser.

Python

Wheels are distributed for many platforms, so you should often be able to just run:

pip install jsonlogic-rs

If a wheel does not exist for your system, this will attempt to build the package. In order for the package to build successfully, you MUST have Rust installed on your local system, and cargo MUST be present in your PATH.

See Building below for more details.

Usage

Rust

use jsonlogic_rs;
use serde_json::json;

// You can pass JSON values deserialized with serde straight
// into apply().
fn main() {
    assert_eq!(
        jsonlogic_rs::apply(
            json!({"===": [{"var": "a"}, 7]}),
            json!({"a": 7}),
        ),
        json!(true)
    );
}

Javascript

const jsonlogic = require("jsonlogic-rs")

jsonlogic.apply(
    {"===": [{"var": "a"}, 7]},
    {"a": 7}
)

Python

import jsonlogic_rs

res = jsonlogic_rs.apply(
    {"===": [{"var": "a"}, 7]},
    {"a": 7}
)

assert res == True

# If You have serialized JsonLogic and data, the `apply_serialized` method can 
# be used instead
res = jsonlogic_rs.apply_serialized(
    '{"===": [{"var": "a"}, 7]}',
    '{"a": 7}'
)

Building

Prerequisites

You must have Rust installed and cargo available in your PATH.

If you would like to build or test the Python distribution, Python 3.6 or newer must be available in your PATH. The venv module must be part of the Python distribution (looking at you, Ubuntu).

If you would like to run tests for the WASM package, node 10 or newer must be available in your PATH.

Rust

To build the Rust library, just run cargo build.

You can create a release build with make build.

WebAssembly

You can build a debug WASM release with

make debug-wasm

You can build a production WASM release with

make build-wasm

The built WASM package will be in js/. This package is directly importable from node, but needs to be browserified in order to be used in the browser.

Python

To perform a dev install of the Python package, run:

make develop-py

This will automatically create a virtual environment in venv/, install the necessary packages, and then install jsonlogic_rs into that environment.

Note: from our CI experiences, this may not work for Python 3.8 on Windows. If you are running this on a Windows machine and can confirm whether or not this works, let us know!

To build a production source distribution:

make build-py-sdist

To build a wheel (specific to your current system architecture and python version):

make build-py-wheel

The python distribution consists both of the C extension generated from the Rust and a thin wrapper found in py/jsonlogic_rs/. make develop-py will compile the C extension and place it in that directory, where it will be importable by your local venv. When building wheels, the wrapper and the C extension are all packaged together into the resultant wheel, which will be found in dist/. When building an sdist, the Rust extension is not compiled. The Rust and Python source are distributed together in a .tar.gz file, again found in dist/.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jsonlogic-rs-0.1.1.tar.gz (32.1 kB view details)

Uploaded Source

Built Distributions

jsonlogic_rs-0.1.1-cp38-cp38-win_amd64.whl (218.5 kB view details)

Uploaded CPython 3.8 Windows x86-64

jsonlogic_rs-0.1.1-cp38-cp38-macosx_10_15_x86_64.whl (267.2 kB view details)

Uploaded CPython 3.8 macOS 10.15+ x86-64

jsonlogic_rs-0.1.1-cp37-cp37m-win_amd64.whl (218.5 kB view details)

Uploaded CPython 3.7m Windows x86-64

jsonlogic_rs-0.1.1-cp37-cp37m-macosx_10_15_x86_64.whl (267.2 kB view details)

Uploaded CPython 3.7m macOS 10.15+ x86-64

jsonlogic_rs-0.1.1-cp36-cp36m-win_amd64.whl (218.5 kB view details)

Uploaded CPython 3.6m Windows x86-64

jsonlogic_rs-0.1.1-cp36-cp36m-macosx_10_15_x86_64.whl (267.2 kB view details)

Uploaded CPython 3.6m macOS 10.15+ x86-64

File details

Details for the file jsonlogic-rs-0.1.1.tar.gz.

File metadata

  • Download URL: jsonlogic-rs-0.1.1.tar.gz
  • Upload date:
  • Size: 32.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3

File hashes

Hashes for jsonlogic-rs-0.1.1.tar.gz
Algorithm Hash digest
SHA256 7c6c89022e90048431b1ab8c91a7f941474c766d29062257a4d2d87e6c47d39b
MD5 a13310008a0234af57ea5858a4d65200
BLAKE2b-256 d4369e13be4b14ff46a388c66c14fb18156e2f4874616f444a79279d5a8ebcb4

See more details on using hashes here.

File details

Details for the file jsonlogic_rs-0.1.1-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: jsonlogic_rs-0.1.1-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 218.5 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3

File hashes

Hashes for jsonlogic_rs-0.1.1-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 a825290b25dab294b774e17b2bcc8ec82e9fa11129fadd949aa7362cd4a8ccb3
MD5 f1c69799ae3778843b68f7f28050d02e
BLAKE2b-256 08e77328d33e1c83d129acb9bd406fdb668a44e4a628755d8567e8a2b8f93514

See more details on using hashes here.

File details

Details for the file jsonlogic_rs-0.1.1-cp38-cp38-macosx_10_15_x86_64.whl.

File metadata

  • Download URL: jsonlogic_rs-0.1.1-cp38-cp38-macosx_10_15_x86_64.whl
  • Upload date:
  • Size: 267.2 kB
  • Tags: CPython 3.8, macOS 10.15+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3

File hashes

Hashes for jsonlogic_rs-0.1.1-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 c1a8d20d33b885d9c38827c3c5cf370799352857b3d43ce9433fa4c4ef87f3aa
MD5 a6714f10d6af7bd9a9eb7225777a0c54
BLAKE2b-256 bb68773985d41da4edbe5508c45520e9d00440852f25107d6810cde3e7ec138a

See more details on using hashes here.

File details

Details for the file jsonlogic_rs-0.1.1-cp37-cp37m-win_amd64.whl.

File metadata

  • Download URL: jsonlogic_rs-0.1.1-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 218.5 kB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3

File hashes

Hashes for jsonlogic_rs-0.1.1-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 453f26316a534cddb7197f4ec4b8da4a26acd4673749bce996f4e89c872b82e2
MD5 b13850e70a6622ca9dea9ed7893c7c3c
BLAKE2b-256 9a887d94a6b68b5e5617dde12e99585626b6c3ab433ddafc9fcf74fa338dc81d

See more details on using hashes here.

File details

Details for the file jsonlogic_rs-0.1.1-cp37-cp37m-macosx_10_15_x86_64.whl.

File metadata

  • Download URL: jsonlogic_rs-0.1.1-cp37-cp37m-macosx_10_15_x86_64.whl
  • Upload date:
  • Size: 267.2 kB
  • Tags: CPython 3.7m, macOS 10.15+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3

File hashes

Hashes for jsonlogic_rs-0.1.1-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 49790b50892d5c4a5dcf310f80066cc604d59cb70da18aa92b7bd3d378a11db4
MD5 ee969416f2fa2e665913fa6cc162a904
BLAKE2b-256 66c28c0e1ab450a2a182ab7a9504957f22718cd27162b70e8e44c7c00e3eb313

See more details on using hashes here.

File details

Details for the file jsonlogic_rs-0.1.1-cp36-cp36m-win_amd64.whl.

File metadata

  • Download URL: jsonlogic_rs-0.1.1-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 218.5 kB
  • Tags: CPython 3.6m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3

File hashes

Hashes for jsonlogic_rs-0.1.1-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 7cd7476f3c7ec3bef53239638d6edd1f2df92b370c68c8c9054bdf7080faa582
MD5 f276a30df5a1f03990119bac4b9d9345
BLAKE2b-256 f9acfe63d0360f82afa5a0a3abd64c15014f46ad3e5be056d1ffc0a7486717a2

See more details on using hashes here.

File details

Details for the file jsonlogic_rs-0.1.1-cp36-cp36m-macosx_10_15_x86_64.whl.

File metadata

  • Download URL: jsonlogic_rs-0.1.1-cp36-cp36m-macosx_10_15_x86_64.whl
  • Upload date:
  • Size: 267.2 kB
  • Tags: CPython 3.6m, macOS 10.15+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3

File hashes

Hashes for jsonlogic_rs-0.1.1-cp36-cp36m-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 e53c6033d070dfe9bd791c1a25c5a9a1759029cbea0b4f85252816db3ee166fa
MD5 a8b3517d15d301458ec18ccd0c1622ca
BLAKE2b-256 f6aac3340b69f69b79e3367f3fdffa92503678b5d260cb81c13812cff38a548c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page