Skip to content

Commit 33c39a1

Browse files
committed
exploring
1 parent f2e817a commit 33c39a1

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

json-java21-jsonpath/src/test/java/json/java21/jsonpath/JsonPathParserTest.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package json.java21.jsonpath;
22

3+
import jdk.sandbox.java.util.json.Json;
4+
import jdk.sandbox.java.util.json.JsonValue;
35
import org.junit.jupiter.api.Test;
46
import org.junit.jupiter.params.ParameterizedTest;
57
import org.junit.jupiter.params.provider.ValueSource;
@@ -315,4 +317,49 @@ void testParseIncompletePathThrows(String path) {
315317
assertThatThrownBy(() -> JsonPathParser.parse(path))
316318
.isInstanceOf(JsonPathParseException.class);
317319
}
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+
}
318365
}

0 commit comments

Comments
 (0)