diff --git a/json-path/src/main/java/com/jayway/jsonpath/JsonPath.java b/json-path/src/main/java/com/jayway/jsonpath/JsonPath.java index d76ede2e..5af8a171 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/JsonPath.java +++ b/json-path/src/main/java/com/jayway/jsonpath/JsonPath.java @@ -158,12 +158,37 @@ public class JsonPath { * * @return true if path is definite (points to single item) */ - public boolean isPathDefinite() { - String preparedPath = getPath().replaceAll("\"[^\"\\\\\\n\r]*\"", ""); + public static boolean isPathDefinite(String path) { + String preparedPath = path.replaceAll("\"[^\"\\\\\\n\r]*\"", ""); return !DEFINITE_PATH_PATTERN.matcher(preparedPath).matches(); } + + /** + * Checks if a path points to a single item or if it potentially returns multiple items + *

+ * a path is considered not definite if it contains a scan fragment ".." + * or an array position fragment that is not based on a single index + *

+ *

+ * definite path examples are: + *

+ * $store.book + * $store.book[1].title + *

+ * not definite path examples are: + *

+ * $..book + * $.store.book[1,2] + * $.store.book[?(@.category = 'fiction')] + * + * @return true if path is definite (points to single item) + */ + public boolean isPathDefinite() { + return JsonPath.isPathDefinite(getPath()); + } + /** * Applies this JsonPath to the provided json document. * Note that the document must be identified as either a List or Map by