Skip to content

Commit ab99e23

Browse files
committed
Issue #126 Simplify JsonPath docs and use mvnw
Promote json-java21-jsonpath docs to README.md and keep it focused on public usage (Goessner spec + basic examples). Update human READMEs to use ./mvnw (with -am when selecting modules) and add a top-level JsonPath pointer.\n\nVerify: ./mvnw test -pl json-java21-jsonpath -am -Djava.util.logging.ConsoleHandler.level=INFO
1 parent 3eadf51 commit ab99e23

File tree

4 files changed

+80
-218
lines changed

4 files changed

+80
-218
lines changed

README.md

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ We welcome contributions to the JTD Validator incubating within this repo.
2020
To try the examples from this README, build the project and run the standalone example class:
2121

2222
```bash
23-
mvn package
23+
./mvnw package
2424
java -cp ./json-java21/target/java.util.json-*.jar:./json-java21/target/test-classes \
2525
jdk.sandbox.java.util.json.examples.ReadmeExamples
2626
```
@@ -257,10 +257,10 @@ The test data is bundled as ZIP files and extracted automatically at runtime:
257257

258258
```bash
259259
# Run human-readable report
260-
mvn exec:java -pl json-compatibility-suite
260+
./mvnw exec:java -pl json-compatibility-suite
261261

262262
# Run JSON output (dogfoods the API)
263-
mvn exec:java -pl json-compatibility-suite -Dexec.args="--json"
263+
./mvnw exec:java -pl json-compatibility-suite -Dexec.args="--json"
264264
```
265265

266266

@@ -368,10 +368,10 @@ The validator provides full RFC 8927 compliance with comprehensive test coverage
368368

369369
```bash
370370
# Run all JTD compliance tests
371-
$(command -v mvnd || command -v mvn || command -v ./mvnw) test -pl json-java21-jtd -Dtest=JtdSpecIT
371+
./mvnw test -pl json-java21-jtd -Dtest=JtdSpecIT
372372

373373
# Run with detailed logging
374-
$(command -v mvnd || command -v mvn || command -v ./mvnw) test -pl json-java21-jtd -Djava.util.logging.ConsoleHandler.level=FINE
374+
./mvnw test -pl json-java21-jtd -Djava.util.logging.ConsoleHandler.level=FINE
375375
```
376376

377377
Features:
@@ -388,7 +388,24 @@ Features:
388388
Requires JDK 21 or later. Build with Maven:
389389

390390
```bash
391-
mvn clean package
391+
./mvnw clean package
392+
```
393+
394+
## JsonPath
395+
396+
This repo also includes a JsonPath query engine (module `json-java21-jsonpath`), based on the original Goessner JSONPath article:
397+
https://goessner.net/articles/JsonPath/
398+
399+
```java
400+
import jdk.sandbox.java.util.json.*;
401+
import json.java21.jsonpath.JsonPath;
402+
403+
JsonValue doc = Json.parse("""
404+
{"store": {"book": [{"author": "A"}, {"author": "B"}]}}
405+
""");
406+
407+
JsonPath path = JsonPath.parse("$.store.book[*].author");
408+
var authors = path.query(doc);
392409
```
393410

394411
See AGENTS.md for detailed guidance including logging configuration.

json-java21-jsonpath/ARCHITECTURE.md

Lines changed: 0 additions & 207 deletions
This file was deleted.

json-java21-jsonpath/README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# JsonPath
2+
3+
This module provides a JSONPath-style query engine for JSON documents parsed with `jdk.sandbox.java.util.json`.
4+
5+
It is based on the original Stefan Goessner JSONPath article:
6+
https://goessner.net/articles/JsonPath/
7+
8+
## Usage
9+
10+
Parse JSON once with `Json.parse(...)`, compile the JsonPath once with `JsonPath.parse(...)`, then query multiple documents:
11+
12+
```java
13+
import jdk.sandbox.java.util.json.*;
14+
import json.java21.jsonpath.JsonPath;
15+
16+
JsonValue doc = Json.parse("""
17+
{"store": {"book": [{"author": "A"}, {"author": "B"}]}}
18+
""");
19+
20+
JsonPath path = JsonPath.parse("$.store.book[*].author");
21+
var authors = path.query(doc);
22+
23+
// If you want a static call site:
24+
var sameAuthors = JsonPath.query(path, doc);
25+
```
26+
27+
Notes:
28+
- Prefer `JsonPath.parse(String)` + `query(JsonValue)` to avoid repeatedly parsing the same path.
29+
- `JsonPath.query(String, JsonValue)` is intended for one-off usage.
30+
31+
## Supported Syntax
32+
33+
This implementation follows Goessner-style JSONPath operators, including:
34+
- `$` root
35+
- `.name` / `['name']` property access
36+
- `[n]` array index (including negative indices)
37+
- `[start:end:step]` slices
38+
- `*` wildcards
39+
- `..` recursive descent
40+
- `[n,m]` and `['a','b']` unions
41+
- `[?(@.prop)]` and `[?(@.prop op value)]` basic filters
42+
- `[(@.length-1)]` limited script support
43+
44+
## Testing
45+
46+
```bash
47+
./mvnw test -pl json-java21-jsonpath -am -Djava.util.logging.ConsoleHandler.level=INFO
48+
```
49+
50+
```bash
51+
./mvnw test -pl json-java21-jsonpath -am -Dtest=JsonPathGoessnerTest -Djava.util.logging.ConsoleHandler.level=FINE
52+
```

json-java21-jtd/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,16 +174,16 @@ Validation errors include standardized information:
174174

175175
```bash
176176
# Build the module
177-
$(command -v mvnd || command -v mvn || command -v ./mvnw) compile -pl json-java21-jtd
177+
./mvnw compile -pl json-java21-jtd -am
178178

179179
# Run tests
180-
$(command -v mvnd || command -v mvn || command -v ./mvnw) test -pl json-java21-jtd
180+
./mvnw test -pl json-java21-jtd -am
181181

182182
# Run RFC compliance tests
183-
$(command -v mvnd || command -v mvn || command -v ./mvnw) test -pl json-java21-jtd -Dtest=JtdSpecIT
183+
./mvnw test -pl json-java21-jtd -am -Dtest=JtdSpecIT
184184

185185
# Run with detailed logging
186-
$(command -v mvnd || command -v mvn || command -v ./mvnw) test -pl json-java21-jtd -Djava.util.logging.ConsoleHandler.level=FINE
186+
./mvnw test -pl json-java21-jtd -am -Djava.util.logging.ConsoleHandler.level=FINE
187187
```
188188

189189
## Architecture
@@ -217,4 +217,4 @@ This implementation is fully compliant with RFC 8927:
217217

218218
## License
219219

220-
This project is part of the OpenJDK JSON API implementation and follows the same licensing terms.
220+
This project is part of the OpenJDK JSON API implementation and follows the same licensing terms.

0 commit comments

Comments
 (0)