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.
This tool bridges the gap between the interpreter and codegen paths:
json-java21-jtd): ideal for infrequent config parsing — simple, no build step, runs on JDK 21+.json-java21-jtd-codegen): ideal for repeated hot-path validation — ~9x faster, but requires JDK 25+ at runtime.Future note:
java.util.jsonhas 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.
jtd2jar <schema.json> [options]
Options:
--output <path>: output JAR path (default: <schema-name>-validator.jar)--package <name>: generated package name (default: jtd.generated)--class <name>: validator class name (default: SchemaValidator)--main: include a standalone java -jar entry point--runtime <version>: target bytecode version (default: 21)--include-sources: write a companion .java file next to the JAR--help: show usageA minimal distroless container image is available for offline schema compilation without a full JDK.
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.30published this image under the misspelled nameghcr.io/simbo1905/java.util.json.java21/jdt2jar. Those tags remain on GHCR but are frozen; re-point tojtd2jar.
Requires Docker and JDK 25+ (for the build stage). Build from the repository root:
docker build -t jtd2jar -f jtd2jar/Dockerfile .
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
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.
gcr.io/distroless/base-debian13:nonrootnonroot (uid 65532)/work (for schema input and JAR output)syft packages image:ghcr.io/simbo1905/java.util.json.java21/jtd2jar:latest
grype ghcr.io/simbo1905/java.util.json.java21/jtd2jar:latest