### Question:
IsJson extends TypeSafeMatcher<T> { public IsJson(Matcher<? super ReadContext> jsonMatcher) { this.jsonMatcher = jsonMatcher; } IsJson(Matcher<? super ReadContext> jsonMatcher); void describeTo(Description description);  }### Answer:
@Test public void shouldMatchOnEmptyJsonObject() { assertThat("{}", isJson()); }
@Test public void shouldMatchOnJsonObject() { assertThat("{ \"hi\" : \"there\" }", isJson()); }
@Test public void shouldMatchOnEmptyJsonArray() { assertThat("[]", isJson()); }
@Test public void shouldMatchOnJsonArray() { assertThat("[\"hi\", \"there\"]", isJson()); }
@Test public void shouldMatchValidJson() { assertThat(VALID_JSON, isJson()); assertThat(BOOKS_JSON_STRING, isJson()); }
@Test public void shouldNotMatchInvalidJson() { assertThat(INVALID_JSON, not(isJson())); assertThat(new Object(), not(isJson())); assertThat(new Object[]{}, not(isJson())); assertThat("hi there", not(isJson())); assertThat(new Integer(42), not(isJson())); assertThat(Boolean.TRUE, not(isJson())); assertThat(false, not(isJson())); assertThat(null, not(isJson())); }
@Test public void shouldMatchJsonObjectEvaluatedToTrue() { assertThat(BOOKS_JSON_PARSED, isJson(withPathEvaluatedTo(true))); }
@Test public void shouldNotMatchJsonObjectEvaluatedToFalse() { assertThat(BOOKS_JSON_PARSED, not(isJson(withPathEvaluatedTo(false)))); }
@Test public void shouldMatchJsonStringEvaluatedToTrue() { assertThat(BOOKS_JSON_STRING, isJson(withPathEvaluatedTo(true))); }
@Test public void shouldNotMatchJsonStringEvaluatedToFalse() { assertThat(BOOKS_JSON_STRING, not(isJson(withPathEvaluatedTo(false)))); }
@Test public void shouldMatchJsonFileEvaluatedToTrue() { assertThat(BOOKS_JSON_FILE, isJson(withPathEvaluatedTo(true))); }
@Test public void shouldNotMatchJsonFileEvaluatedToFalse() { assertThat(BOOKS_JSON_FILE, not(isJson(withPathEvaluatedTo(false)))); }
@Test public void shouldNotMatchNonExistingJsonFile() { File nonExistingFile = new File("missing-file"); assertThat(nonExistingFile, not(isJson())); }
@Test public void shouldDescribeMismatchOfValidJson() { Matcher<Object> matcher = isJson(withPathEvaluatedTo(true)); Description description = new StringDescription(); matcher.describeMismatch(BOOKS_JSON_STRING, description); assertThat(description.toString(), containsString(TestingMatchers.MISMATCHED_TEXT)); }
@Test public void shouldDescribeMismatchOfInvalidJson() { Matcher<Object> matcher = isJson(withPathEvaluatedTo(true)); Description description = new StringDescription(); matcher.describeMismatch("invalid-json", description); assertThat(description.toString(), containsString("\"invalid-json\"")); }