You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
|`json-compatibility-suite`| JSON Test Suite conformance reporter (tests against [nst/JSONTestSuite](https://github.com/nst/JSONTestSuite)) | 21+ |
21
22
|`json-java21-api-tracker`| Daily upstream API drift detector — fetches OpenJDK sandbox sources, compares public API signatures, reports differences | 25+ |
@@ -335,9 +336,12 @@ Such vulnerabilities existed at one point in the upstream OpenJDK sandbox implem
335
336
336
337
## JSON Type Definition (JTD) Validator
337
338
338
-
This repo contains an incubating JTD validator that has the core JSON API as its only dependency. This sub-project demonstrates how to build realistic JSON heavy logic using the API. It follows Data Oriented Programming principles: it compiles JTD schemas into an immutable structure of records. For validation it parses the JSON document to the generic structure and uses the thread-safe parsed schema and a stack to visit and validate the parsed JSON.
339
+
This repo includes two JTD validation paths for different use cases:
339
340
340
-
A complete JSON Type Definition validator is included (module: json-java21-jtd).
341
+
-**Interpreter** ([`json-java21-jtd`](json-java21-jtd/README.md)) — stack-machine validator for infrequent config parsing and one-time validation. Runs on JDK 21+ with zero extra dependencies.
342
+
-**Bytecode codegen** ([`json-java21-jtd-codegen`](json-java21-jtd-codegen/README.md)) — generates dedicated validator classes for repeated hot-path validation (~9x faster). Requires JDK 24+ at build time; generated classes run on JDK 21+.
343
+
344
+
> `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 with zero library overhead.
341
345
342
346
### Empty Schema `{}` Semantics (RFC 8927)
343
347
@@ -349,43 +353,19 @@ Per **RFC 8927 (JSON Typedef)**, the empty schema `{}` is the **empty form** and
349
353
> `empty = {}`
350
354
> **Empty form:** A schema in the empty form accepts all JSON values and produces no errors.
351
355
352
-
⚠️ Note: Some tools or in-house validators mistakenly interpret `{}` as "object with no
353
-
properties allowed." **That is not JTD.** This implementation follows RFC 8927 strictly.
354
-
355
356
```java
356
357
importjson.java21.jtd.Jtd;
357
358
importjdk.sandbox.java.util.json.*;
358
359
359
-
// Compile JTD schema
360
-
JsonValue schema =Json.parse("""
361
-
{
362
-
"properties": {
363
-
"name": {"type": "string"},
364
-
"age": {"type": "int32"}
365
-
}
366
-
}
367
-
""");
368
-
369
-
// Validate JSON
370
-
JsonValue data =Json.parse("{\"name\":\"Alice\",\"age\":30}");
An optional `jdt2jar` CLI tool and distroless Docker image are available for pre-compiling JTD schemas into standalone validator JARs at build time. This eliminates the JDK 24+ runtime requirement for generated validators — the JARs run on JDK 21+.
380
+
381
+
See [`jdt2jar/README.md`](jdt2jar/README.md) for build instructions, container usage, and the pre-built image on GitHub Container Registry (`ghcr.io`).
`jdt2jar` compiles a JTD schema into a standalone validator JAR at build time. The generated JAR runs on JDK 21+ with no JDK 24+ runtime dependency.
4
+
5
+
## Use Case
6
+
7
+
This tool bridges the gap between the interpreter and codegen paths:
8
+
9
+
-**Interpreter** ([`json-java21-jtd`](../json-java21-jtd/README.md)): ideal for infrequent config parsing — simple, no build step, runs on JDK 21+.
10
+
-**Codegen** ([`json-java21-jtd-codegen`](../json-java21-jtd-codegen/README.md)): ideal for repeated hot-path validation — ~9x faster, but requires JDK 24+ at runtime.
11
+
-**jdt2jar**: pre-compiles schemas into validator JARs at build time (using JDK 24+), then deploys them to any JDK 21+ runtime. Best for CI/CD pipelines, distroless containers, or environments where you want JIT-optimised validators without shipping a JDK 24+ runtime.
12
+
13
+
> **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.
14
+
15
+
## CLI
16
+
17
+
```bash
18
+
jdt2jar <schema.json> [options]
19
+
```
20
+
21
+
Options:
22
+
23
+
-`--output <path>`: output JAR path (default: `<schema-name>-validator.jar`)
24
+
-`--package <name>`: generated package name (default: `jtd.generated`)
25
+
-`--class <name>`: validator class name (default: `SchemaValidator`)
26
+
-`--main`: include a standalone `java -jar` entry point
27
+
-`--runtime <version>`: target bytecode version (default: 21)
28
+
-`--include-sources`: write a companion `.java` file next to the JAR
29
+
-`--help`: show usage
30
+
31
+
## Container Image
32
+
33
+
A minimal distroless container image is available for offline schema compilation without a full JDK.
0 commit comments