count members with jsonpath?

前端 未结 5 1087
生来不讨喜
生来不讨喜 2020-12-22 20:42

Is it possible to count the number of members using JsonPath?

Using spring mvc test I\'m testing a controller that generates

{\"foo\": \"oof\", \"ba         


        
5条回答
  •  甜味超标
    2020-12-22 21:36

    You can also use the methods inside the jsonpath, so instead of

    mockMvc.perform(get(API_URL))
       .andExpect(jsonPath("$.*", hasSize(2)));
    

    you can do

    mockMvc.perform(get(API_URL))
       .andExpect(jsonPath("$.length()", is(2)));
    

提交回复
热议问题