{"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":"en","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,"last_verified":"2026-04-10T00:00:00.000Z","next_check":"2026-07-09T00:00:00.000Z"}