Java Code Examples for com.jayway.jsonpath.JsonPath#getPath()

The following examples show how to use com.jayway.jsonpath.JsonPath#getPath() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JsonEngine.java    From client-encryption-java with MIT License 5 votes vote down vote up
/**
 * Get JSON path to the parent of the object at the given JSON path.
 */
public static String getParentJsonPath(String jsonPathString) {
    JsonPath jsonPath = JsonPath.compile(jsonPathString);
    String compiledPath = jsonPath.getPath();
    Matcher matcher = LAST_ELEMENT_IN_PATH_PATTERN.matcher(compiledPath);
    if (matcher.find()) {
        return compiledPath.replace(matcher.group(1), "");
    }
    throw new IllegalStateException(String.format("Unable to find parent for '%s'", jsonPathString));
}
 
Example 2
Source File: JsonEngine.java    From client-encryption-java with MIT License 5 votes vote down vote up
/**
 * Get object key at the given JSON path.
 */
public static String getJsonElementKey(String jsonPathString) {
    JsonPath jsonPath = JsonPath.compile(jsonPathString);
    String compiledPath = jsonPath.getPath();
    Matcher matcher = LAST_ELEMENT_IN_PATH_PATTERN.matcher(compiledPath);
    if (matcher.find()) {
        return matcher.group(1).replace("['", "").replace("']", "");
    }
    throw new IllegalStateException(String.format("Unable to find object key for '%s'", jsonPathString));
}
 
Example 3
Source File: JsonPathValue.java    From spring-cloud-contract with Apache License 2.0 4 votes vote down vote up
JsonPathValue(JsonPath jsonPath, CharSequence actual) {
	this.jsonPath = jsonPath;
	this.actual = actual;
	this.expression = jsonPath.getPath();
}
 
Example 4
Source File: RequestVerifierFilter.java    From spring-cloud-netflix with Apache License 2.0 4 votes vote down vote up
JsonPathValue(JsonPath jsonPath, CharSequence actual) {
	this.jsonPath = jsonPath;
	this.actual = actual;
	this.expression = jsonPath.getPath();
}