# Extracting Conditional Response Values

**URL:** <https://community.gatling.io/t/extracting-conditional-response-values/741>\
**Category:** Gatling (Open-Source)\
**Created:** [December 20, 2013, 10:53pm UTC](https://community.gatling.io/t/extracting-conditional-response-values/741 "2013-12-20T22:53:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kirstin\_Rhys](https://avatars.discourse-cdn.com/v4/letter/k/4bbf92/32.png) [@Kirstin\_Rhys](https://community.gatling.io/u/Kirstin_Rhys)\
**Post date:** [December 20, 2013, 10:53pm UTC](https://community.gatling.io/t/extracting-conditional-response-values/741/1 "2013-12-20T22:53:47Z")

</div>

Hi Stéphane,

First, I just wanted to say how much I loved Gatling!

Suppose one needed to save into the session, for later execution branching, values which might not always be present.

For instance, given a JSON response such as:

{success=“true”}

It’s easy to extract and save. But suppose we could also get a response like this:

{success=“false”; error\_code=123}

We’d like to branch chains based on the value of error\_code. But checking for it directly will give us a KO (if some simulations got success=true), even if this is expected, and we succeed on the branch we take.

I take it the correct approach would be to do something like

def xformMaybeV : Option[V]

check(bodyString.transform(xform)).saveAs(“maybeValue”)

Note, this is for 2.0. Also, gatling works very nicely as a library–I’m sure many people would love to use it for functional testing.

Thanks,

kirstin

---

<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:** [December 21, 2013, 9:11am UTC](https://community.gatling.io/t/extracting-conditional-response-values/741/2 "2013-12-21T09:11:36Z")

</div>

Hi,

Thanks for you kind words.

Actually, that’s something you already have, even in Gatling 1, see step named “whatever” in Check API:  
[https://github.com/excilys/gatling/wiki/Checks#wiki-whatever](https://github.com/excilys/gatling/wiki/Checks#wiki-whatever)

(beware that it has been renamed into “dontValidate” in next Gatling 2 milestone.

So:

- have a check (JsonPath is probably the best solution for your use case) on error\_code
- then, you can branch with a “doIf(\_.contains(“error\_code”))”  
Cheers,

Stéphane
