how to use a correlated value in next json request

Hi All,

i have captured a jwt token and massaged it to get a parameter from it. I want to use this parameter in the next json request but it doesn’t resolve the variable as in below format.

Below is the way I am capturing the variable (roomsourceid) from thw jwt token (token1)

val decodedToken:String = JWSObject.parse(token1).getPayload.toString
roomSourceid = JsonPath.from(decodedToken).getString(“roomSourceId”)

Next request json :


“sample1”: “${roomSourceid}”,
“sample2”: “${roomSourceid}”


The roomsourceid in the above json is not getting resolved. Any help appreciated. thank you !


you shall be using session if you want to share any data between your requests, for example:

  1. Get and save the access_token received from authenticate url within the session:
private def authenticateUser: ChainBuilder = exec(
http("Get bearer")
.basicAuth(session => "login", session => "password")
  1. Use the saved access token in another request:
private def uploadFile: ChainBuilder = exec(
http("Upload file")
.header("Authorization", "Bearer ${access_token}")
  1. Coordinate requests within the scenario:
private def uploadFileScenario(shallRevokeTokenForEachUser: Boolean): ScenarioBuilder =
scenario(s"Get bearer and upload file").exec(

I hope it helps you,

Thanks Daniil,

In the above example, we are capturing the value using .check and that is possible. In my case, i am saving the access_token, massaging it (decode the jwt and pick a variable like roomSourceId from it) and then I am trying to use it in next request. In this way, its not resolving when i use ${ roomSourceId}, i am able to print this in a exec session, but cannot use it in the request.

Please share the full code. You’re most likely not properly storing the extracted data back into the Session.

Hello Stephane,

Please find the code below.

.check(regex(“leftboundary(.*?)&rightboundary”).saveAs(“token”)))) //this token is jwt
.exec({ session =>
val token1 = session(“token”).as[String]
val decodedToken:String = JWSObject.parse(token1).getPayload.toString
roomid = JsonPath.from(decodedToken).getString(“roomSourceId”)
println(“Room source id is” +roomSourceid)
.post("/url to hit")

“roomSourceId”: ${roomSourceid},
“preferredPhone” : “800-888-8888”,
.check(status is 200))

In Request-3, the value of roomSourceid is not getting resolved. Its getting printed fine in the previous step, i am sure i am missing something with the variable/session. Appreciate your help !!

Either what you’ve provided is not the actual code you’re using, or this code is completely broken.

roomid = JsonPath.from(decodedToken).getString(“roomSourceId”)

This means you’ve defined roomId elsewhere as a var, meaning a global shared variable that all the virtual users will share and try to update without any concurrent access protection.

What you must do is put the decoded value back into the Session:

.exec({ session =>
val token1 = session(“token”).as[String]

val decodedToken:String = JWSObject.parse(token1).getPayload.toString

val roomSourceid = JsonPath.from(decodedToken).getString(“roomSourceId”)
println(“Room source id is” +roomSourceid)
session.set(“roomSourceid”, roomSourceid)

Thank you so much Stephane. Yes, you are right, I messed up with the variables. thank you for pointing it out.