@Test public void computePathFunction() { String content = "{ 'a' : 'X', 'b' : 'Z' }"; String query = "$.length()"; // $.a.length() does not work; need to understand Object result = JsonPathUtils.computePathFunction(query, content); assertThat(result, equalTo(2)); }
/** * Produces the results of applying a function-based (e.g., length()) JsonPath query to Json * content. * * @param queryPath The JsonPath query * @param content The Json content * @return An @{link Object} that represents the answer */ public static Object computePathFunction(String queryPath, String content) { return computePathFunctionPvt( queryPath, JsonPath.parse(content, BatfishJsonPathDefaults.getDefaulConfiguration()).json()); }
/** * Produces the results of applying JsonPath query to Json content. This function does not support * arithmetic functions (e.g., length() in queries. * * @param queryPath The JsonPath query * @param content The Json content * @return A list of @{link JsonPathResult} entities */ public static List<JsonPathResult> getJsonPathResults(String queryPath, String content) { return getJsonPathResultsPvt( queryPath, JsonPath.parse(content, BatfishJsonPathDefaults.getDefaulConfiguration()).json()); }
JsonPathUtils.computePathFunction(extraction.getFilter(), jpResult.getSuffix()); if (result != null) { if (result instanceof Integer) { JsonPathUtils.getJsonPathResults(extraction.getFilter(), jpResult.getSuffix()); for (JsonPathResult result : filterResults) { JsonNode value =
@Test public void getJsonPathResults() { String content = "{ 'a' : 'X', 'b' : 'Z' }"; String query = "$.a"; List<JsonPathResult> results = JsonPathUtils.getJsonPathResults(query, content); assertThat(results.size(), equalTo(1)); assertThat(results.get(0).getSuffix(), equalTo(new TextNode("X"))); } }
JsonPathUtils.getJsonPathResults(query.getPath(), innerAnswer);
/** * Produces the results of applying JsonPath query to Json content. This function does not support * arithmetic functions (e.g., length() in queries. * * @param queryPath The JsonPath query * @param content The Json content * @return A list of @{link JsonPathResult} entities */ public static List<JsonPathResult> getJsonPathResults(String queryPath, JsonNode content) { return getJsonPathResultsPvt( queryPath, JsonPath.parse(content, BatfishJsonPathDefaults.getDefaulConfiguration()).json()); }
/** * Produces the results of applying a function-based (e.g., length()) JsonPath query to Json * content. * * @param queryPath The JsonPath query * @param content The Json content * @return An @{link Object} that represents the answer */ public static Object computePathFunction(String queryPath, JsonNode content) { return computePathFunctionPvt( queryPath, JsonPath.parse(content, BatfishJsonPathDefaults.getDefaulConfiguration()).json()); }