### Evaluate JsonLogic Expression in Java Source: https://github.com/jamsesso/json-logic-java/blob/main/README.md Instantiate JsonLogic, set up a JSON expression and data map, then apply the expression to evaluate the result. The JsonLogic instance is thread-safe. ```java // Create a new JsonLogic instance. JsonLogic is thread safe. JsonLogic jsonLogic = new JsonLogic(); // Set up some JSON and some data. String expression = "{\"*": [{\"var\": \"x\"}, 2]}"; Map data = new HashMap<>(); data.put("x", 10); // Evaluate the result. double result = (double) jsonLogic.apply(expression, data); assert result == 20.0; ``` -------------------------------- ### Add json-logic-java Dependency Source: https://github.com/jamsesso/json-logic-java/blob/main/README.md Include this XML snippet in your Maven project's pom.xml to add the json-logic-java dependency. ```xml io.github.jamsesso json-logic-java 1.1.0 ``` -------------------------------- ### Check Truthiness with Javascript Rules Source: https://github.com/jamsesso/json-logic-java/blob/main/README.md Use the static truthy method to mimic Javascript's truthiness rules for various data types. This is useful for consistent logic evaluation across different environments. ```java assert JsonLogic.truthy(0) == false; assert JsonLogic.truthy(1) == true; assert JsonLogic.truthy("") == false; assert JsonLogic.truthy("Hello world!") == true; // etc... ``` -------------------------------- ### Add Custom Operation to JsonLogic Source: https://github.com/jamsesso/json-logic-java/blob/main/README.md Register a custom operation with the JsonLogic instance using addOperation. The provided lambda function will be executed when the custom operation is encountered in an expression. ```java // Register an operation. jsonLogic.addOperation("greet", (args) -> "Hello, " + args[0] + "!"); // Evaluate the result. String result = (String) jsonLogic.apply("{\"greet\": [\"Sam\"]}", null); assert "Hello, Sam!".equals(result); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.