JSON serializable rules to match Jackson JsonNodes using JSON Pointers.
{
"type": "equals",
"value": "happy",
"path": "$.mood"
}
{
"name": "John Doe",
"mood": "happy"
}
Payload would match the rules when evaluated
Maven repo
<dependency>
<groupId>io.appform.rules</groupId>
<artifactId>json-rules</artifactId>
<version>1.0.8</version>
</dependency>
// Build expression with java objects
Expression expression = LessThanExpression.builder()
.path("/$.value")
.value(30)
.build();
// Or read from serialized json sources
Expression expression = (new ObjectMapper()).readValue(expressionJson, Expression.class)
// Get json payload to be evaluated
JsonNode jsonNode = objectMapper.readTree(productJson);
boolean matches = expression.evaluate(jsonNode);
{
"type": "equals",
"value": "happy",
"path": "$.mood"
}
{
"type": "and",
"children": [
{
"type": "equals",
"value": "happy",
"path": "$.mood"
},
{
"type": "less_than",
"value": 1000,
"path": "$.product.cost"
}
]
}
{
"type": "in",
"path": "$.mood",
"values": [
"happy",
"sad"
]
}
The string operations of starts_with
, ends_with
and matches
support case insensitive comparison also. Default comparison is case sensitive.
{
"type": "matches",
"path": "$.s1",
"value": ".* WORLD",
"ignoreCase" : true
}
For unstructured json evaluation you can specify a defaultResult value.
The default value would be the evaluation result if path
doesn't exist in the evaluation payload.
{
"type": "equals",
"value": "happy",
"path": "$.mood",
"defaultResult": true
}
Pre-operations are pre-evaluation mutations that can be applied to payload.
{
"type": "in",
"path": "$.time",
"preoperation": {
"operation": "epoch",
"operand": "week_of_month",
"zoneOffSet": "+05:30"
},
"values": [
2,
4
]
}
These allow comparison of dynamic values. Using "extractValueFromPath" : true
, indicates the value to be used for comparison has to be extracted from value
json path.
{
"type": "matches",
"path": "$.s1",
"value": "$.s2",
"extractValueFromPath" : true
}
Can you improve this documentation?Edit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close