I'm trying to get a specific array item not by the array position, but by the content key.
Example JSON:
{"items": [{
"key": "prop-name",
"label": "Provider",
"type": "DROPDOWN",
"items": ["bla", "blub", "what", "ever"]
}, {
"key": "prop-modes",
"label": "Transport modes",
"type": "CHECKBOX",
"items": ["AIR", "RAIL", "ROAD", "SEA"]
}
]}
private static String URL_GLOBAL_FILTER = "/global-filter";
private static String PROP_NAME = "prop-name";
mvc.perform(get(URL_GLOBAL_FILTER).contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk())
.andExpect(jsonPath("$.items", hasSize(10)))
.andExpect(jsonPath("$.items[?((@.key === \"" + PROP_NAME + "\" && @.type === \"DROPDOWN\"))]").exists())
.andExpect(jsonPath("$.items[0].items", hasSize(4)));
This works perfectly fine. But what I want to do is something like:
.andExpect(jsonPath("$.items[?(@.key == \"prop-name\")].items", containsString("bla")))
But that throws the following error:
java.lang.AssertionError: JSON path "$.items[?(@.key == "prop-name")].items"
Expected: a string containing "bla" but: was a net.minidev.json.JSONArray (<[["bla","blub","what","ever"]]>)
What does the < > mean? How to access the array inside?
In jsonQueryTool it seems to be what I want.
(UPDATED question)