js-to-json-logic
This is a Python library that parses a JavaScript expression and converts it into a JsonLogic-compatible object.
This is useful for cases where you want to allow users to input logical expressions in a familiar syntax, but you want to evaluate them using JsonLogic.
This library is inspired by the JavaScript library js-to-json-logic.
Usage
from json_logic import jsonLogic
from js_to_json_logic import transform_js
rule = transform_js("a > 5 && b < 10")
result = jsonLogic(rule, {"a": 6, "b": 8})
print(result) # True
Supported JavaScript Syntax
| Type | Example |
|---|---|
| Literals | 42, "hello", true, false, null |
| Identifiers | a, b, myObject.property |
| Template literals | `Hello, ${name}!` |
| Arrays | [1, 2, 3], [1, 2, ...rest] |
| Unary operations | !a, !!b, -x, +x |
| Conditionals | a > 5, b < 10, c >= 15 |
| Arithmetic | a + b, a - b, a * b, a / b, a % b |
| Equality and inequality | a == 5, b !== 10, c === 15, d !== 20 |
| Logical expressions | a && b, a || b |
| If statements | if (a > 10) { "large" } else if (a > 5) { "medium" } else { "small" } |
| Ternaries | a > 5 ? "yes" : "no" |
| Call expressions | myFunction(a, b) |
| Regex literals | /^abc$/gi |
| Arrow functions | x => x > 5 |
License
This project is licensed under the terms of the MIT license.
Metadata
Release files for js-to-json-logic 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| js_to_json_logic-0.1.0.tar.gz | 4.8 kB | Without provenance | Details for js_to_json_logic-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| js_to_json_logic-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for js_to_json_logic-0.1.0-py3-none-any.whl |
Total release size: 11.1 kB
Release files / js_to_json_logic-0.1.0.tar.gz
| Download URL | js_to_json_logic-0.1.0.tar.gz |
|---|---|
| Size | 4.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8c250d6d3ade774850b83d020bd6f35f9afec9cb9b4d9b5f045461d87ad9bdee
|
|
BLAKE2b-256 checksum How to use checksums |
31ef69d14f0267605e83947ef76e981bd775f29f0709e9afee0cc3c8897bbe2c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / js_to_json_logic-0.1.0-py3-none-any.whl
| Download URL | js_to_json_logic-0.1.0-py3-none-any.whl |
|---|---|
| Size | 6.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
673e89efbdc546288b92e6096c4d1ff096e11483e7485fcacaec984287242bc8
|
|
BLAKE2b-256 checksum How to use checksums |
8f9d8f93720296f022f36dbd49dbfb4fe9fb111f7681eec027d297d9899577a4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for js-to-json-logic 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.