I am working with RestAssured
framework in my java
project but i got an error from Groovy
. I need to find a bunch of elements in my json
. My json looks like as below:
[ {
"city" : "LONDON",
"car" : "myCar",
"name" : "Jack",
"familyName" : "Joe"
} ]
Here is how i make the keys to search on json:
List<String> gfg = new ArrayList<>(List.of("$.[0].city", "$.[0].car", "$.[0].name", "$.[0].familyName"));
for (String path : jsonPaths) {
String key = "\"" + path + "\"";
Assert.assertTrue(rawRes.jsonPath().getString(key) != null);
}
Here the rawRes
is the Response type from RestAssured
framework which contains the json in its body.
But then in the line rawRes.jsonPath().getString(key)
it complains with:
Script1.groovy: 1: illegal string body character after dollar sign;
solution: either escape a literal dollar sign "\$5" or bracket the value expression "${5}" @ line 1, column 29.
restAssuredJsonRootObject."$.[0].endTimeLocal"