{"id":2550,"library":"json-logic","title":"JSON-Logic","description":"json-logic-py is a Python implementation of JsonLogic, a lightweight JSON-based rules engine. It allows users to build complex logic rules using a JSON structure, serialize them, and execute them in Python to evaluate data. The current version is 0.6.3, and it appears to be in a stable maintenance phase with infrequent updates, requiring Python 3.6+.","status":"active","version":"0.6.3","language":"python","source_language":"en","source_url":"https://github.com/nadirizr/json-logic-py","tags":["json-logic","rules-engine","logic","json","decision-engine"],"install":[{"cmd":"pip install json-logic","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"note":"The PyPI package name is 'json-logic', but the module to import is 'json_logic' (note the underscore instead of hyphen).","symbol":"jsonLogic","correct":"from json_logic import jsonLogic"}],"quickstart":{"code":"from json_logic import jsonLogic\n\nrules = {\n    \"and\": [\n        {\"<\": [1, 2]},\n        {\">\": [1, 0]}\n    ]\n}\n\ndata = {}\nresult = jsonLogic(rules, data)\nprint(f\"Result: {result}\")\n\n# Example with actual data\nuser_data = {\"temp\": 100, \"humidity\": 50}\nrules_with_var = {\n    \"and\": [\n        {\"<\": [{\"var\": \"temp\"}, 150]},\n        {\"<=\": [{\"var\": \"humidity\"}, 60]}\n    ]\n}\nresult_with_data = jsonLogic(rules_with_var, user_data)\nprint(f\"Result with data: {result_with_data}\")","lang":"python","description":"This quickstart demonstrates how to define a JsonLogic rule using a Python dictionary and evaluate it against a data context. It shows a basic boolean evaluation and an example using the 'var' operator to access data."},"warnings":[{"fix":"Review existing rules that use the `in` operator and ensure they are intended to operate on lists. If string substring checking is needed, implement it with custom logic or different operators.","message":"The behavior of the `in` operator changed in version 0.6.0. Previously, it might have checked for substring presence in a string. Since 0.6.0, `in` strictly checks for element presence within a list.","severity":"breaking","affected_versions":"0.6.0 and higher"},{"fix":"Always consult the official JsonLogic specification or examples to ensure correct rule syntax, especially for complex or nested conditions.","message":"JsonLogic rules must strictly adhere to the defined JSON structure, where operator keys are always single keys in an object, and their values are arrays of arguments. Deviations will lead to errors or unexpected behavior.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Sanitize or validate incoming rules. Consider implementing limits on rule complexity (e.g., nesting depth, number of operations) if rules are user-provided.","message":"When receiving JsonLogic rules from untrusted sources (e.g., user input), there's a potential for logic bombs or resource exhaustion if highly complex or deeply nested rules are submitted. While the library itself doesn't execute arbitrary code, poorly constructed rules can still impact performance.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure `json_logic.add_operation('my_operator', my_function)` is called for each custom operator before evaluating any rules that use it.","message":"Custom operators must be explicitly registered with the `add_operation` function before they can be used in your rules. They are not automatically discovered.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"search_vec":"'0.6.3':47 '3.6':63 'allow':22 'appear':50 'base':18 'build':25 'complex':26 'current':44 'data':42 'decis':73 'decision-engin':72 'engin':20,69,74 'evalu':41 'execut':36 'implement':11 'infrequ':59 'json':2,5,17,31,65,71 'json-bas':16 'json-log':1,64 'json-logic-pi':4 'jsonlog':13 'lightweight':15 'logic':3,6,27,66,70 'mainten':56 'phase':57 'py':7 'python':10,39,62 'requir':61 'rule':19,28,68 'rules-engin':67 'serial':33 'stabl':55 'structur':32 'updat':60 'use':29 'user':23 'version':45","created_at":"2026-04-11T01:32:50.534549+00:00","updated_at":"2026-04-16T15:54:42.616666+00:00","problems":[{"fix":"Upgrade the `json-logic` library to a newer version or a compatible fork that has addressed this Python 3 incompatibility, or convert the `dict_keys` object to a list before indexing if modifying the library's source.","cause":"This error occurs in Python 3.x when the library attempts to directly access elements of a `dict_keys` object (returned by `dict.keys()`) using an index, as `dict_keys` is an iterable view and not subscriptable like a list. This was a known issue in older versions of the `json-logic-py` library (version 0.6.3 specifically).","error":"TypeError: 'dict_keys' object does not support indexing"},{"fix":"Add `from json_logic import jsonLogic` at the beginning of your Python script or module to import the function.","cause":"The `jsonLogic` function, which is the main entry point for evaluating rules, was called without being properly imported from the `json_logic` module.","error":"NameError: name 'jsonLogic' is not defined"},{"fix":"Install the library using pip: `pip install json-logic` or `pip install json-logic-py` (depending on the project's pypi name, `json-logic` is the correct one for nadirizr's project). Correct the import statement if there's a typo.","cause":"The `json-logic` package (which provides the `json_logic` module) is not installed in the current Python environment, or there is a typo in the import statement.","error":"ModuleNotFoundError: No module named 'json_logic'"},{"fix":"Check the spelling of the operator in your JSON rule against the list of supported operators (e.g., from jsonlogic.com or the library's documentation). If it's a custom operator, ensure it has been correctly added to the operations registry.","cause":"The JSON logic rule provided contains an operator that is not recognized or supported by the `json-logic-py` library's default operations.","error":"Unrecognized operation %s"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"0.6.3","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/nadirizr/json-logic-py","docs":null,"changelog":null,"pypi":"https://pypi.org/project/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-08-28","next_check":"2026-07-28","install_tag":null}}