> For the complete documentation index, see [llms.txt](https://bernardo.gitbook.io/development-docs-java/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://bernardo.gitbook.io/development-docs-java/testing-spring/testing/testing-json.md).

# Testing JSON

Using this:

```java
result = mockMvc.perform(get);
```

## Print JSON

```java
result.andDo(MockMvcResultHandlers.print());
```

## Get JSON

```java
result.andReturn().getResponse().getContentAsString();
```

## Check Number of Elements

```java
result.andExpect(MockMvcResultMatchers.jsonPath("$.content", Matchers.hasSize(1)));
```

## Check String

```java
result.andExpect(MockMvcResultMatchers.jsonPath("$.content", Matchers.equalTo("text")));
```

```java
result.andExpect(MockMvcResultMatchers.content().string("text"));
```
