JSONata reference ported to Java
This is a 1:1 Java port of the JSONata reference implementation
- 100% JSONata feature compatibility
- All JSONata language features supported
- 100% reference test coverage with well justified exceptions
- Error messages matching the reference
- Even stack traces are comparable
- Zero dependency and small
- Only 160 kB total size
- JSON parser agnostic
- use with Jackson, GSon, ...
- comes with integrated vanilla parser
- Performance optimized & thread safe
- Enterprise support
jsonata-java is built by Dashjoin, the open source platform for data and AI apps.
Add the dependency in pom.xml:
<dependency>
<groupId>com.dashjoin</groupId>
<artifactId>jsonata</artifactId>
<version>0.9.11</version>
</dependency>Here is the release change log
Main.java program:
import java.util.List; import java.util.Map;
import static com.dashjoin.jsonata.Jsonata.jsonata;
public class Main {
public static void main(String[] args) {
var data = Map.of("example",
List.of(
Map.of("value", 4),
Map.of("value", 7),
Map.of("value", 13)
)
);
var expression = jsonata("$sum(example.value)");
var result = expression.evaluate(data); // returns 24
System.out.println(result);
}
}You can define custom functions and declare variables via a JSONata frame or the registerFunction method:
var expression = jsonata("$sum(example.value) + $sin($PI/2)");
// Default JSONata has no $sin function and no $PI, so define it
var env = expression.createFrame();
env.bind("sin", (