use of com.jayway.jsonpath.JsonPath in project pentaho-kettle by pentaho.
the class FastJsonReader method compilePaths.
private static JsonPath[] compilePaths(JsonInputField[] fields) {
JsonPath[] paths = new JsonPath[fields.length];
int i = 0;
for (JsonInputField field : fields) {
paths[i++] = JsonPath.compile(field.getPath());
}
return paths;
}
use of com.jayway.jsonpath.JsonPath in project camel by apache.
the class JsonPathEngine method read.
public Object read(Exchange exchange) throws Exception {
if (path == null) {
Expression exp = exchange.getContext().resolveLanguage("simple").createExpression(expression);
String text = exp.evaluate(exchange, String.class);
JsonPath path = JsonPath.compile(text);
LOG.debug("Compiled dynamic JsonPath: {}", expression);
return doRead(path, exchange);
} else {
return doRead(path, exchange);
}
}
use of com.jayway.jsonpath.JsonPath in project jmeter by apache.
the class JSONManager method extractWithJsonPath.
/**
* @param jsonString JSON String from which data is extracted
* @param jsonPath JSON-PATH expression
* @return List of JSON Strings of the extracted data
* @throws ParseException when parsing fails
*/
public List<Object> extractWithJsonPath(String jsonString, String jsonPath) throws ParseException {
JsonPath jsonPathParser = getJsonPath(jsonPath);
List<Object> extractedObjects;
try {
extractedObjects = jsonPathParser.read(jsonString, DEFAULT_CONFIGURATION);
} catch (PathNotFoundException e) {
if (log.isDebugEnabled()) {
log.debug("Could not find JSON Path {} in [{}]: {}", jsonPath, jsonString, e.getLocalizedMessage());
}
return Collections.emptyList();
}
List<Object> results = new ArrayList<>(extractedObjects.size());
for (Object obj : extractedObjects) {
results.add(stringifyJSONObject(obj));
}
return Collections.unmodifiableList(results);
}
use of com.jayway.jsonpath.JsonPath in project batfish by batfish.
the class JsonPathTest method testPath4.
@Test
public void testPath4() {
JsonPath jsonPath = JsonPath.compile("$.nodes[*][?([\"1.2.3.4\"] subsetof @.loggingServers)].loggingServers");
assertThat(jsonPath, not(equalTo(nullValue())));
}
use of com.jayway.jsonpath.JsonPath in project batfish by batfish.
the class JsonPathTest method testOneNtpServerPresent.
@Test
public void testOneNtpServerPresent() {
String path = "$.nodes[*][?(!([\"1.2.3.4\"] subsetof @.ntpServers))].ntpServers";
JsonPath jsonPath = JsonPath.compile(path);
ArrayNode prefixes = null;
try {
prefixes = jsonPath.read(_oneNtpServerNodesAnswerJsonObject, _prefixConfiguration);
} catch (PathNotFoundException e) {
prefixes = JsonNodeFactory.instance.arrayNode();
}
assertThat(prefixes, not(equalTo(nullValue())));
assertThat(prefixes.size(), equalTo(0));
}
Aggregations