Skip to content

About

JSONata reference ported to Java

Topics

Resources

Security policy

Stars

104 stars

Watchers

4 watching

Forks

Repository files navigation

jsonata-java is the JSONata Java reference port

JSONata reference ported to Java

This is a 1:1 Java port of the JSONata reference implementation

Features

Built by Dashjoin

jsonata-java is built by Dashjoin, the open source platform for data and AI apps.

Quick Start

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);
    }
}

Custom Functions

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", (