I am using Gatling and want to extract JSON from the response body and then use jsonPath on that. To be clear the response is something like this:
<html>
<!-- usual stuff here -->
<script>
/* JSON I WANT TO EXTRACT */
{
var1:'val1',
var2:'val2'
}
</script>
<!-- rest of HTML content -->
</html>
I am able to get the JSON using regex:
val chain = exec(http("Homepage")
.get("/")
.check(regex("""myJsonRegex""").find(1).saveAs("responseJSON"))
That's not the actual regex, but not the point, the regex works and I can isolate the JSON, but I would really like to use jsonPath on that saved "responseJSON", not sure how to do that. I can probably just do the whole thing with regex, but it would be much cleaner with jsonPath.
You could use circe
or more specifically circe-optics
for that. The documentation has a few decent examples.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.