Skip to content

kommradHomer/json-logic-java

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 

Repository files navigation

json-logic-java

A Java implementation of http://jsonlogic.com/

Maven

A maven release has not yet been made as the library is still under development

<dependencies>
  <dependency>
    <groupId>com.northernwall</groupId>
    <artifactId>json-logic-java</artifactId>
    <version>1.0.0</version>
    <type>jar</type>
  </dependency>
</dependencies>

Usage

One Time Evaluation

String rule = "{\"cat\": [\"I love \", {\"var\":\"filling\"}, \" pie"\]}";
String data = "{"filling":"apple", "temp":110}";
Result result = jsonLogic.apply(rule, data);

Reuse A Rule With different data

String rule = "{\"cat\": [\"I love \", {\"var\":\"filling\"}, \" pie"\]}";
JsonLogicTree tree = jsonLogic.parse(rule);

Result result1 = tree.evaluate("{"filling":"apple", "temp":110}");
Result result2 = tree.evaluate("{"filling":"blueberry", "temp":120}");
Result result3 = tree.evaluate("{"filling":"key lime", "temp":115}");

Tests

There are 108 test cases that are contained within the file "BulkTests.txt". Some of the test cases are from http://jsonlogic.com/operations.html while other I wrote. Each line in the file represents a test or a comment. Each line has 2 or 3 components sperated by a tab. The first component is the JsonLogic expression, the second (optional) component is the JSON data object, and the last component is the expected result.

All 108 test cases Pass

About

A Java implementation of http://jsonlogic.com/

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 100.0%