use of com.jayway.jsonpath.Filter in project JsonPath by jayway.
the class FilterTest method combine_filter_deep_criteria.
@Test
public void combine_filter_deep_criteria() {
String json = "[\n" + " {\n" + " \"first-name\" : \"John\",\n" + " \"last-name\" : \"Irving\",\n" + " \"address\" : {\"state\" : \"Texas\"}\n" + " },\n" + " {\n" + " \"first-name\" : \"Jock\",\n" + " \"last-name\" : \"Ewing\",\n" + " \"address\" : {\"state\" : \"Texas\"}\n" + " },\n" + " {\n" + " \"first-name\" : \"Jock\",\n" + " \"last-name\" : \"Barnes\",\n" + " \"address\" : {\"state\" : \"Nevada\"}\n" + " } \n" + "]";
Filter filter = filter(where("first-name").is("Jock").and("address.state").is("Texas"));
List<Map<String, Object>> jocksInTexas1 = JsonPath.read(json, "$[?]", filter);
List<Map<String, Object>> jocksInTexas2 = JsonPath.read(json, "$[?(@.first-name == 'Jock' && @.address.state == 'Texas')]");
JsonPath.parse(json).json();
assertThat((String) JsonPath.read(jocksInTexas1, "$[0].address.state"), is("Texas"));
assertThat((String) JsonPath.read(jocksInTexas1, "$[0].first-name"), is("Jock"));
assertThat((String) JsonPath.read(jocksInTexas1, "$[0].last-name"), is("Ewing"));
}
use of com.jayway.jsonpath.Filter in project JsonPath by jayway.
the class IssuesTest method issue_129.
@Test
public void issue_129() throws Exception {
final Map<String, Integer> match = new HashMap<String, Integer>();
match.put("a", 1);
match.put("b", 2);
Map<String, Integer> noMatch = new HashMap<String, Integer>();
noMatch.put("a", -1);
noMatch.put("b", -2);
Filter orig = filter(where("a").eq(1).and("b").eq(2));
String filterAsString = orig.toString();
Filter parsed = Filter.parse(filterAsString);
assertThat(orig.apply(createPredicateContext(match))).isTrue();
assertThat(parsed.apply(createPredicateContext(match))).isTrue();
assertThat(orig.apply(createPredicateContext(noMatch))).isFalse();
assertThat(parsed.apply(createPredicateContext(noMatch))).isFalse();
}
Aggregations