# Storing a random json return value

**URL:** https://community.gatling.io/t/storing-a-random-json-return-value/508
**Category:** Gatling (Open-Source)
**Created:** [July 26, 2013, 1:23pm UTC](https://community.gatling.io/t/storing-a-random-json-return-value/508 "2013-07-26T13:23:16Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Roy\_van\_der\_Valk](https://avatars.discourse-cdn.com/v4/letter/r/ba8739/32.png) [@Roy\_van\_der\_Valk](https://community.gatling.io/u/Roy_van_der_Valk)
#### Post date: [July 26, 2013, 1:23pm UTC](https://community.gatling.io/t/storing-a-random-json-return-value/508/1 "2013-07-26T13:23:16Z")

</div>

Dear all,

I one of my previous question I asked how I could build a generic function that knows how to manipulate the default requests outputted by the recorder. I’ve build this as suggested by Stéphane by making a generic http function. Simplified it looks as follows.

> def httpInterpreted(name: String, url: EvaluatableString, headers: Map[String,String], requestBodyFile: String) =  
> {  
> def defaultHttp …  
> def customHttp …  
> …  
> requestType match  
> {  
> case “instantiate” =\> customHttp(List(“objecttype”))  
> .check(jsonPath(“$…guid”).saveAs(“guid”))  
> case “retrieve\_by\_xpath”=\> customHttp(List(“xpath”, “schema”, “count”, “aggregates”))  
> .check(jsonPath(“$…mxobjects.guid”).find( **?random?** ).whatever.saveAs(“guid”))  
> …  
> case \_ =\> defaultHttp  
> }  
> }

I want to store one random guid of all the ones returned. I know how to do [this](https://github.com/excilys/gatling/wiki/Session#building-session-functions-) in this way, by building a session function, but than I have to do it for every request. I think it would be need to also use some generic solution for this.

I tried passing the session to this function and retrieving the session member and editing it, but it didn’t work. My guess is the session members (in this case ${guid}), aren’t accessible only after the whole http method is executed or am I wrong?

Do you have any idea for solving this issue?

Cheers,  
Roy

---

<div class="post-metadata">

### Author: ![Excilys](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@Excilys](https://community.gatling.io/u/Excilys)
#### Post date: [July 26, 2013, 1:33pm UTC](https://community.gatling.io/t/storing-a-random-json-return-value/508/2 "2013-07-26T13:33:41Z")

</div>

Why don’t you findAll of them, and pick one randomly in a transform step directly into your check? [https://github.com/excilys/gatling/wiki/Checks#wiki-transforming](https://github.com/excilys/gatling/wiki/Checks#wiki-transforming)

---

<div class="post-metadata">

### Author: ![Roy\_van\_der\_Valk](https://avatars.discourse-cdn.com/v4/letter/r/ba8739/32.png) [@Roy\_van\_der\_Valk](https://community.gatling.io/u/Roy_van_der_Valk)
#### Post date: [July 26, 2013, 1:47pm UTC](https://community.gatling.io/t/storing-a-random-json-return-value/508/3 "2013-07-26T13:47:58Z")

</div>

Didn’t know about this functionality. Great! Have a nice weekend!

---

<div class="post-metadata">

### Author: ![Excilys](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@Excilys](https://community.gatling.io/u/Excilys)
#### Post date: [July 26, 2013, 1:48pm UTC](https://community.gatling.io/t/storing-a-random-json-return-value/508/4 "2013-07-26T13:48:56Z")

</div>

You’re welcome. You too!
