Extracting JSON response

Using Firefox RESTClient gives me the response(body) attached as screenshot.
Wanting to save i.e the “scanNumber” in this response, how do I write that in Gatling?
I have tried

.check(jsonPath("//“scanNumber”:"").saveAs(“responsevar”)))

But get error:

14:14:36.019 [WARN ] i.g.h.a.AsyncHandlerActor - Request ‘Login page’ failed: jsonPath(“scanNumber”:"").exists failed, could not extract: could not extract : $' expected but ’ found

Is there a way to print to console (in i.e IntelliJ) the reponse I am getting in the Simulation? This would be helpful.

Given that I have managed to save the response “responsevar” above is there an easy way to also print this to console in i.e IntelliJ?

Magnus

And here is the screenshot.

Magnus

Click on link on documentation and check the proper syntax.
JsonPath ≠ XPath

Looking at http://gatling.io/docs/2.0.0-RC5/http/http_check.html
this is still not clear to me.

Could you please elaborate? JSON is different from XPath, ok. But I miss a concrete example in the documentation.

Thanks,
Magnus

https://github.com/gatling/gatling/blob/master/gatling-core/src/test/scala/io/gatling/core/check/extractor/jsonpath/JsonPathExtractorSpec.scala

Right,
I did make this work:

.check(jsonPath("$.resultCode").is(“SUCCESS”)))

But this:

.check(jsonPath("$.memberships.scanNumber").saveAs(“scanNr”)))

returns:

jsonPath($.memberships.scanNumber).exists, found nothing 5 (100,0%)

I guess I am getting closer, do I need the .check ? It should find “something” looking at the JSON response again:

{"resultCode":"SUCCESS","errorCode":null,"errorMessage":null,"profile":{"fullName":"TestFirstName TestMiddleName TestLastName","memberships":[{"name":"UA Gold Partner","number":"123-456-123-123","scanNumber":"123-456-123-123"}]}}

memberships is an array : $.memberships[0].scanNumber

Still not working with:

.check(jsonPath("$.memberships[0].scanNumber").findAll.saveAs(“scanNr”)))

But this worked:

.check(jsonPath("$.profile.memberships[0].scanNumber").findAll.saveAs(“scanNr”)))

Thank you guys!

Woops : $.profile.memberships[0].scanNumber

For further info on JsonPath: http://goessner.net/articles/JsonPath/ (link is provided in the documentation).
You can also easily find online JSONpath expression testers.

Thanks,
is it a simple way to print the value of scanNumber saved as the variable “scanNr” in my question.
print to console in IntelliJ i.e.?

Cheers,
Magnus

Add a session lambda to your scenario to print your value stored in the session, after it’s set by your check:

exec(session => {
println(session(“scanNr”).as[String])
session
})