java.util.json Backport for JDK 21+

Early Access: This is an unofficial backport of the experimental java.util.json API from OpenJDK sandbox, enabling developers to use future JSON API patterns today on JDK 21+.

Quick Start

Maven Dependency


            <dependency>
                <groupId>io.github.simbo1905.json</groupId>
                <artifactId>java.util.json</artifactId>
                <version>0.1.8</version>
            </dependency>
        

Simple Example

import jdk.sandbox.java.util.json.*;

// Parse JSON
JsonValue value = Json.parse("{\"name\":\"Alice\",\"age\":30}");
JsonObject obj = (JsonObject) value;

// Access values
String name = ((JsonString) obj.members().get("name")).value();
int age = ((JsonNumber) obj.members().get("age")).toNumber().intValue();

Key Features

Record Mapping Example

// Domain model
record User(String name, String email, boolean active) {}
record Team(String teamName, List<User> members) {}

// Convert to JSON
Team team = new Team("Engineering", List.of(
    new User("Alice", "alice@example.com", true),
    new User("Bob", "bob@example.com", false)
));

JsonValue teamJson = Json.fromUntyped(Map.of(
    "teamName", team.teamName(),
    "members", team.members().stream()
        .map(u -> Map.of(
            "name", u.name(),
            "email", u.email(),
            "active", u.active()
        ))
        .toList()
));

Resources

View on GitHub Original Proposal OpenJDK Sandbox

Status

This code (as of 2025-09-04) is derived from the OpenJDK jdk-sandbox repository “json” branch at commit Produce path/col during path building. The API may evolve as the official specification develops.

License

Licensed under the GNU General Public License version 2 with Classpath exception, same as the OpenJDK project.