Use JsonPath matchers for assertions
masterTo use the library, statically import com.jayway.jsonpath.matchers.JsonPathMatchers.*. The matchers work with Strings, Files, or already parsed JSON objects. Note that the evaluation depends on your current Configuration settings.
import static com.jayway.jsonpath.matchers.JsonPathMatchers.*;
// Supported JSON representations:
String json = ...;
File json = ...;
Object json = Configuration.defaultConfiguration().jsonProvider().parse(content);
// Basic assertions
assertThat(json, isJson());
assertThat(json, hasJsonPath("$.message"));
assertThat(json, hasNoJsonPath("$.message"));
// Value assertions
assertThat(json, hasJsonPath("$.message", equalTo("Hi there")));
assertThat(json, hasJsonPath("$.quantity", equalTo(5)));
assertThat(json, hasJsonPath("$.store.book[*].author", hasSize(4)));
assertThat(json, hasJsonPath("$.store.book[*].author", hasItem("Evelyn Waugh")));