How to retrieve data from json response

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,

Hi,

To extract values from a response, you have to use checks: https://github.com/excilys/gatling/wiki/Advanced-Usage#wiki-session and 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 :wink:

Cheers,
BluePyth

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

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>

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