1414/// ```java
1515/// // Fluent API (preferred)
1616/// JsonValue json = Json.parse(jsonString);
17- /// List<JsonValue> results = JsonPath.parse("$.store.book[*].author").select (json);
17+ /// List<JsonValue> results = JsonPath.parse("$.store.book[*].author").query (json);
1818///
19- /// // Static query API
20- /// List<JsonValue> results = JsonPath.query("$.store.book[*].author", json);
19+ /// // Compiled + static call site (also reusable)
20+ /// JsonPath path = JsonPath.parse("$.store.book[*].author");
21+ /// List<JsonValue> results = JsonPath.query(path, json);
2122/// ```
2223///
23- /// Based on the JSONPath specification from https://goessner.net/articles/JsonPath/
24+ /// Based on the JSONPath specification from [...]( https://goessner.net/articles/JsonPath/)
2425public final class JsonPath {
2526
2627 private static final Logger LOG = Logger .getLogger (JsonPath .class .getName ());
@@ -49,9 +50,23 @@ public static JsonPath parse(String path) {
4950 /// @param json the JSON document to query
5051 /// @return a list of matching JsonValue instances (may be empty)
5152 /// @throws NullPointerException if json is null
53+ /// @deprecated Use `query(JsonValue)` (aligns with Goessner JSONPath terminology).
54+ @ Deprecated (forRemoval = false )
5255 public List <JsonValue > select (JsonValue json ) {
56+ return query (json );
57+ }
58+
59+ /// Queries matching values from a JSON document.
60+ ///
61+ /// This is the preferred instance API: compile once via `parse(String)`, then call `query(JsonValue)`
62+ /// for each already-parsed JSON document.
63+ ///
64+ /// @param json the JSON document to query
65+ /// @return a list of matching JsonValue instances (may be empty)
66+ /// @throws NullPointerException if json is null
67+ public List <JsonValue > query (JsonValue json ) {
5368 Objects .requireNonNull (json , "json must not be null" );
54- LOG .fine (() -> "Selecting from document with path: " + pathExpression );
69+ LOG .fine (() -> "Querying document with path: " + pathExpression );
5570 return evaluate (ast , json );
5671 }
5772
@@ -65,14 +80,14 @@ public JsonPathAst.Root ast() {
6580 return ast ;
6681 }
6782
68- /// Evaluates a JsonPath expression against a JSON document (convenience method) .
69- /// @param path the JsonPath expression
83+ /// Evaluates a compiled JsonPath against a JSON document.
84+ /// @param path a compiled JsonPath (typically cached)
7085 /// @param json the JSON document to query
7186 /// @return a list of matching JsonValue instances (may be empty)
7287 /// @throws NullPointerException if path or json is null
73- /// @throws JsonPathParseException if the path is invalid
74- public static List < JsonValue > query ( String path , JsonValue json ) {
75- return parse ( path ). select (json );
88+ public static List < JsonValue > query ( JsonPath path , JsonValue json ) {
89+ Objects . requireNonNull ( path , "path must not be null" );
90+ return path . query (json );
7691 }
7792
7893 /// Evaluates a pre-parsed JsonPath AST against a JSON document.
0 commit comments