Although JSONPath Extractor does not provide a hasSize function hasSize it can still be done.
Given the JSON example from the PMD UBIK-INGENIERIE answer, you can get the number of matches in the book array in at least two ways:
1. The easiest (but fragile) way is to use the Regular Expression Extractor .
As you can see, in category 4 entries:
{ "category": "reference", { \"category\": \"fiction\" ...
If you added a regular expression extractor configured as follows:

It will capture all category entries and return the number of matches, as shown below:

This way you can use this variable ${matches_matchNr} wherever you need it.
This approach is simple and easy to implement, but it is very vulnerable to any changes in the response format. If you expect JSON data to change in the foreseeable future, continue to the next option.
2. A more complicated (but more stable) way is to call JsonPath methods from Beanshell PostProcessor
JMeter has a Beanshell scripting extension mechanism that has access to all variables / properties in scope, as well as to the base dependencies of JMeter and third-party dependencies. In this case, you can call the JsonPath library (which is located under the hood of the JsonPath Extractor) directly from Beanshell PostProcessor.
import com.jayway.jsonpath.Criteria; import com.jayway.jsonpath.Filter; import com.jayway.jsonpath.JsonPath; Object json = new String(data); List categories = new ArrayList(); categories.add("fiction"); categories.add("reference"); Filter filter = Filter.filter(Criteria.where("category").in(categories)); List books = JsonPath.read(json, "$.store.book[?]", new Filter[] {filter}); vars.put("JSON_ARRAY_SIZE", String.valueOf(books.size()));
The above code evaluates the JSONPath $.store.book[?] response of the parent sampler, counts the number of matches and stores it in the ${JSON_ARRAY_SIZE} JMeter variable.

which can subsequently be reused in an if clause or statement.
Recommendations: