String jsonResponse = """
[
{
"vi": ["Khoá đào tạo miễn phí", 4],
"en": ["Free training courses", 4]
},
{
"vi": ["Miễn phí giao hàng", 2],
"en": ["Free delivery", 2],
}
]
""";
From the JSON response above I need to get the values of the key “vi” then store them in a List<String, Object>.
I’ve tried using $..vi in https://jsonpath.com/ and got the correct result.
When trying the Java code below, however, I always get Exception in thread “main” java.lang.IllegalArgumentException: The parameter “vi” was used but not defined. Define parameters using the JsonPath.params(…) function.
JsonPath jsonPath = JsonPath.from(jsonResponse);
List<Map<String, Object>> perks = jsonPath.get("$..vi");
I do know that RestAssured in Java uses Gpath notation but I’m stuck on how to get my code working.
I’m using Java RestAssured and Jackson API.
I’ve tried using $..vi in https://jsonpath.com/ and got the correct result.
When trying the Java code below, however, I always get Exception in thread “main” java.lang.IllegalArgumentException: The parameter “vi” was used but not defined. Define parameters using the JsonPath.params(…) function.
JsonPath jsonPath = JsonPath.from(jsonResponse);
List<Map<String, Object>> perks = jsonPath.get("$..vi");