Hope is a high level language for predicate evaluation on JSON written in java. It uses jackson for json handling and json-path for value extraction.
"$.val" + 2 > 3
"$.a" + "$.b" <= math.abs("$.c")
Hope in deployed in clojure maven repository. To use hope, please add the following to <repository/>
section of your pom.xml file.
<repository>
<id>clojars</id>
<name>Clojars repository</name>
<url>https://clojars.org/repo</url>
</repository>
Use the following dependency in your code.
<dependency>
<groupId>io.appform.hope</groupId>
<artifactId>hope-lang</artifactId>
<packaging>pom</packaging>
<version>1.0.4</version>
</dependency>
The following steps can be used to parse and evaluate a predicate expression or rule.
The main class you need to know is HopeLangEngine
. To use this class use the provided builder.
final HopeLangEngine hope = HopeLangEngine.builder()
.build();
Note: Creation of this class is a time consuming affair. Create and resue this. This class is thread-safe.
The following code snippet evaluates an expression against a parsed jackson Json node.
final JsonNode root = new ObjectMapper().readTree("{\"val\" : 10 }");
final String expr = " \"$.val\" + 2 > 9";
if(engine.evaluate(expr, root)) {
...
}
For real life use cases, rule should be parsed only once and cached. Same cached rule can be evaluated multiple times by passing different payloads. See wiki for more details.
Please go through the hope wiki for detailed documentation
Hope is licensed under Apache License Version 2.0
Can you improve this documentation?Edit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close