# How to retrieve data from json response

**URL:** <https://community.gatling.io/t/how-to-retrieve-data-from-json-response/42>\
**Category:** Gatling (Open-Source)\
**Created:** [February 17, 2012, 11:57am UTC](https://community.gatling.io/t/how-to-retrieve-data-from-json-response/42 "2012-02-17T11:57:34Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Paul\_Langeard](https://avatars.discourse-cdn.com/v4/letter/p/b9e5f3/32.png) [@Paul\_Langeard](https://community.gatling.io/u/Paul_Langeard)\
**Post date:** [February 17, 2012, 11:57am UTC](https://community.gatling.io/t/how-to-retrieve-data-from-json-response/42/1 "2012-02-17T11:57:34Z")

</div>

Hi I just begin to use Gatling to test a restFull json web service. I need to retrieve dynamically fields from json body.  
I try with regex without success. For example I want to extract the token value from :  
{“token”:“0726088db3b09d152dfc83a44159dd59f7c72aaa”,“duration”:3600}

Thanks,

---

<div class="post-metadata">

**Author:** ![Romain\_Sertelon](https://avatars.discourse-cdn.com/v4/letter/r/48db29/32.png) [@Romain\_Sertelon](https://community.gatling.io/u/Romain_Sertelon)\
**Post date:** [February 17, 2012, 12:36pm UTC](https://community.gatling.io/t/how-to-retrieve-data-from-json-response/42/2 "2012-02-17T12:36:53Z")

</div>

Hi,

To extract values from a response, you have to use checks: [https://github.com/excilys/gatling/wiki/Advanced-Usage#wiki-session](https://github.com/excilys/gatling/wiki/Advanced-Usage#wiki-session) and [https://github.com/excilys/gatling/wiki/Checks-Reference](https://github.com/excilys/gatling/wiki/Checks-Reference)

As for your problem, I think you should use a regex check:

http(…)…  
.check( regex("""“token”:"(\w)"""").saveAs(“akey”) )

I’m not sure my regex is good (can’t test it) but it’s somthing like that 😉

Cheers,  
BluePyth

---

<div class="post-metadata">

**Author:** ![Hugo\_Cordier](https://avatars.discourse-cdn.com/v4/letter/h/ac8455/32.png) [@Hugo\_Cordier](https://community.gatling.io/u/Hugo_Cordier)\
**Post date:** [February 17, 2012, 12:41pm UTC](https://community.gatling.io/t/how-to-retrieve-data-from-json-response/42/3 "2012-02-17T12:41:43Z")

</div>

Hi,  
That regex should work : regex("""“token”:"([^"]\*)""")  
Hugo

---

<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:** [February 17, 2012, 1:00pm UTC](https://community.gatling.io/t/how-to-retrieve-data-from-json-response/42/4 "2012-02-17T13:00:14Z")

</div>

Beware that if you use the txt format, there’s a bug that requires \ character to be escaped, so you have to write \.  
txt format will be dropped in 1.1.

2012/2/17 Romain Sertelon \<[bluepyth@gmail.com](mailto:bluepyth@gmail.com)\>

---

<div class="post-metadata">

**Author:** ![Paul\_Langeard](https://avatars.discourse-cdn.com/v4/letter/p/b9e5f3/32.png) [@Paul\_Langeard](https://community.gatling.io/u/Paul_Langeard)\
**Post date:** [February 17, 2012, 1:28pm UTC](https://community.gatling.io/t/how-to-retrieve-data-from-json-response/42/5 "2012-02-17T13:28:19Z")

</div>

Many thanks,  
check(regex("""“token”:"([^"]\*)""").saveAs(“token”)) works fine.
