{"id":6023,"library":"panzi-json-logic","title":"panzi-json-logic: JsonLogic and CertLogic Implementation","description":"panzi-json-logic is a Pure Python 3 implementation of JsonLogic and CertLogic. It aims to closely emulate the behavior of the JavaScript JsonLogic specification, including specific operator semantics. The library facilitates sharing declarative rules (logic) between frontend and backend applications, storing them in databases, and evaluating them reliably across different environments. It is currently at version 1.0.1 and appears to be in a maintenance phase, focusing on correctness and compliance with the JsonLogic standard.","status":"maintenance","version":"1.0.1","language":"python","source_language":"en","source_url":"https://github.com/panzi/panzi-json-logic","tags":["JsonLogic","CertLogic","rules engine","pure python","logic","declarative"],"install":[{"cmd":"pip install panzi-json-logic","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"note":"The primary evaluation function `jsonLogic` is directly imported from the `json_logic` package.","wrong":"import json_logic","symbol":"jsonLogic","correct":"from json_logic import jsonLogic"}],"quickstart":{"code":"from json_logic import jsonLogic\n\n# Simple rule evaluation\nrule_simple = { \"==\": [1, 1] }\nresult_simple = jsonLogic(rule_simple)\nprint(f\"Simple rule (1 == 1): {result_simple}\")\n\n# Data-driven rule evaluation\nrule_data = { \">\": [{ \"var\": \"temp\" }, 100] }\ndata = { \"temp\": 105 }\nresult_data = jsonLogic(rule_data, data)\nprint(f\"Data-driven rule (temp > 100 with temp=105): {result_data}\")\n\n# Custom operations (example: using UTF16_SUBSTR for JS-like substr behavior)\nfrom json_logic.builtins import UTF16_SUBSTR\ncustom_operations = { 'substr_utf16': UTF16_SUBSTR }\nrule_substr = { 'substr_utf16': ['hello world', 0, 5] }\nresult_substr = jsonLogic(rule_substr, operations=custom_operations)\nprint(f\"Custom substr (hello world, 0, 5): {result_substr}\")","lang":"python","description":"Demonstrates basic rule evaluation, including a data-driven example and how to register a custom operation, such as the UTF-16 specific substring implementation."},"warnings":[{"fix":"If strict JavaScript `substr` emulation is required, import and use `json_logic.builtins.UTF16_SUBSTR` as a custom operation: `from json_logic.builtins import UTF16_SUBSTR; jsonLogic(rule, operations={'substr': UTF16_SUBSTR})`.","message":"The `substr` operator in `panzi-json-logic` operates on Unicode code points, which differs from the `json-logic-js` JavaScript implementation that operates on UTF-16 code units. This can lead to different string slicing behavior for certain non-ASCII strings.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always use `===` for strict type-and-value equality comparisons to avoid implicit type coercion behavior.","message":"The `==` operator attempts to emulate JavaScript's loose equality, which performs type coercion. This can lead to unexpected results if Python's strict `==` behavior is anticipated. For strict equality, use the `===` operator.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure all JsonLogic rule definitions strictly adhere to the JSON specification. Use a JSON linter or validator for complex rules.","message":"JsonLogic rules are standard JSON. Common JSON syntax errors (e.g., trailing commas, unquoted keys, single quotes instead of double quotes, incorrect casing for `true`/`false`/`null`) will cause parsing failures before the logic can be evaluated.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"search_vec":"'1.0.1':67 '3':17 'across':59 'aim':24 'appear':69 'applic':50 'backend':49 'behavior':29 'certlog':7,22,86 'close':26 'complianc':80 'correct':78 'current':64 'databas':54 'declar':43,92 'differ':60 'emul':27 'engin':88 'environ':61 'evalu':56 'facilit':41 'focus':76 'frontend':47 'implement':8,18 'includ':35 'javascript':32 'json':3,11 'jsonlog':5,20,33,83,85 'librari':40 'logic':4,12,45,91 'mainten':74 'oper':37 'panzi':2,10 'panzi-json-log':1,9 'phase':75 'pure':15,89 'python':16,90 'reliabl':58 'rule':44,87 'semant':38 'share':42 'specif':34,36 'standard':84 'store':51 'version':66","created_at":"2026-04-14T18:38:36.861382+00:00","updated_at":"2026-04-16T19:07:40.057866+00:00","problems":[{"fix":"Install the package using pip: `pip install panzi-json-logic`","cause":"The `panzi-json-logic` package has not been installed or is not accessible in the current Python environment.","error":"ModuleNotFoundError: No module named 'json_logic'"},{"fix":"Ensure the logic passed to `evaluate()` is a dictionary, structured as `{\"operator\": [arguments, ...]}`.","cause":"The logic argument passed to `JsonLogic().evaluate()` is not a dictionary (e.g., a list or string), but the library expects a dictionary where the key is an operator.","error":"TypeError: 'list' object has no attribute 'items'"},{"fix":"Use one of the standard JsonLogic operators (e.g., `and`, `or`, `==`, `>`, `<`, `+`, `-`) or register a custom operator using `JsonLogic().add_operator('my_op', my_function)`.","cause":"The logic dictionary contains an operator key that is not recognized or supported by the `panzi-json-logic` library, either due to a typo or an attempt to use a non-standard operator without defining it.","error":"KeyError: 'unknown_operator_name'"},{"fix":"Ensure that the data passed to operators has compatible types. Pre-process the input data to convert types as needed before evaluation.","cause":"An arithmetic or comparison operator in the JsonLogic rule is attempting to operate on incompatible data types (e.g., adding a string to an integer), leading to a Python `TypeError` during evaluation.","error":"TypeError: unsupported operand type(s) for +: 'str' and 'int'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"1.0.1","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/panzi/panzi-json-logic","docs":null,"changelog":null,"pypi":"https://pypi.org/project/panzi-json-logic/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["serialization"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-06-28","next_check":"2026-07-28","install_tag":null}}