|
1 | 1 | package json.java21.jsonpath; |
2 | 2 |
|
| 3 | +import jdk.sandbox.java.util.json.Json; |
| 4 | +import jdk.sandbox.java.util.json.JsonValue; |
3 | 5 | import org.junit.jupiter.api.Test; |
4 | 6 | import org.junit.jupiter.params.ParameterizedTest; |
5 | 7 | import org.junit.jupiter.params.provider.ValueSource; |
@@ -315,4 +317,49 @@ void testParseIncompletePathThrows(String path) { |
315 | 317 | assertThatThrownBy(() -> JsonPathParser.parse(path)) |
316 | 318 | .isInstanceOf(JsonPathParseException.class); |
317 | 319 | } |
| 320 | + |
| 321 | + public static void main(String[] args) { |
| 322 | + final var storeDoc = """ |
| 323 | + { "store": { |
| 324 | + "book": [ |
| 325 | + { "category": "reference", |
| 326 | + "author": "Nigel Rees", |
| 327 | + "title": "Sayings of the Century", |
| 328 | + "price": 8.95 |
| 329 | + }, |
| 330 | + { "category": "fiction", |
| 331 | + "author": "Evelyn Waugh", |
| 332 | + "title": "Sword of Honour", |
| 333 | + "price": 12.99 |
| 334 | + }, |
| 335 | + { "category": "fiction", |
| 336 | + "author": "Herman Melville", |
| 337 | + "title": "Moby Dick", |
| 338 | + "isbn": "0-553-21311-3", |
| 339 | + "price": 8.99 |
| 340 | + }, |
| 341 | + { "category": "fiction", |
| 342 | + "author": "J. R. R. Tolkien", |
| 343 | + "title": "The Lord of the Rings", |
| 344 | + "isbn": "0-395-19395-8", |
| 345 | + "price": 22.99 |
| 346 | + } |
| 347 | + ], |
| 348 | + "bicycle": { |
| 349 | + "color": "red", |
| 350 | + "price": 19.95 |
| 351 | + } |
| 352 | + } |
| 353 | + } |
| 354 | + """; |
| 355 | + |
| 356 | + final JsonValue doc = Json.parse(storeDoc); |
| 357 | + |
| 358 | + final var path = args.length > 0 ? args[0] : "$.store.book"; |
| 359 | + final var matches = JsonPath.query(path, doc); |
| 360 | + |
| 361 | + System.out.println("path: " + path); |
| 362 | + System.out.println("matches: " + matches.size()); |
| 363 | + matches.forEach(v -> System.out.println(Json.toDisplayString(v, 2))); |
| 364 | + } |
318 | 365 | } |
0 commit comments