java.util.json.Java21

jtd2jar

jtd2jar compiles a JTD schema into a standalone validator JAR at build time. The generated JAR runs on JDK 21+ with no JDK 25+ runtime dependency.

Use Case

This tool bridges the gap between the interpreter and codegen paths:

Future note: java.util.json has entered the JDK incubator (jdk.incubator.json). Once the API stabilises in the JDK itself, generated bytecode validators can depend directly on future JDK classes rather than this backport, making them even more efficient with zero library overhead.

CLI

jtd2jar <schema.json> [options]

Options:

Container Image

A minimal distroless container image is available for offline schema compilation without a full JDK.

Pre-built Image (GitHub Container Registry)

docker pull ghcr.io/simbo1905/java.util.json.java21/jtd2jar:latest
docker pull ghcr.io/simbo1905/java.util.json.java21/jtd2jar:2026.05.20

Name change: releases up to and including 2026.08.30 published this image under the misspelled name ghcr.io/simbo1905/java.util.json.java21/jdt2jar. Those tags remain on GHCR but are frozen; re-point to jtd2jar.

Build Locally

Requires Docker and JDK 25+ (for the build stage). Build from the repository root:

docker build -t jtd2jar -f jtd2jar/Dockerfile .

Usage

The container’s working directory is /work. Mount your project directory there:

docker run --rm -v "$(pwd):/work" jtd2jar:latest schema.jtd.json --output schema-validator.jar --main

Validate a payload with the generated JAR:

java -jar schema-validator.jar --validate payload.json

Or validate inside a container:

docker run --rm -v "$(pwd):/work" --entrypoint /jre/bin/java jtd2jar:latest -jar /work/schema-validator.jar --validate /work/payload.json

Helper Script

For environments where volume mounts are restricted (e.g., Colima on macOS with projects outside ~/), use the helper script:

./scripts/jtd2jar.sh schema.jtd.json --output schema-validator.jar --main

The script syncs source to ~/tmp/jtd2jar-work, runs the container, and syncs output back.

Image Properties

Security Scanning

syft packages image:ghcr.io/simbo1905/java.util.json.java21/jtd2jar:latest
grype ghcr.io/simbo1905/java.util.json.java21/jtd2jar:latest