ELFileBody as an expected output


I would like to compare JSON response with expected output in ELFileBody
(I need to pass values from session to my .json template files and I don’t want to use jsonPath).
For check:



I receive failed comparison result:


Request ‘xxx’ failed: bodyString.find.is([
“id”: 777
]), but actually found [{“id”:777}]


Any idea for easy way to make response and expected output comparable?

Either format your file in a way that matches the actual response, instead of being prettyfied, or transform the ElFileBody (it’s a Expression[String]) and map it to unprettyfy.

Hi Stephane,

Yes, it’s obvious for me what should I do with that, but I don’t now how to use transform method for ELFileBody. Could you provide an example how to do it?

Hi again,

Meanwhile I found solution which is sufficient for my purposes:


import io.gatling.core.session._
import io.gatling.core.Predef._
import io.gatling.http.Predef._
import io.gatling.core.json.Jackson.TheObjectMapper

object Draft {

val Default = “data/default.json”

def toJsonString(str: String) = TheObjectMapper

val scn = scenario(“Draft”)

.exec(http(“Get sth”)

.transform(str => toJsonString(str))
.is(ELFileBody(Default).map(str => toJsonString(str)))


I transformed both expected result and response to Json string format. The only issue was whitespaces which were making files not comparable, so I removed all of them from both strings.
If anyone found any prettier way to solve this, please, share it here. Thanks in advance.


HI, I have the same problem with you, even I copied the json string from the log, It also doesn’t work.
So I use your code but get error as below, it seems I don’t have the “TheObjectMapper” class. cloud you help me figure out. thank you

19:29:20.958 [ERROR] i.g.c.ZincCompiler$ - /Users/kang.hua/Downloads/gatling_API/user-files/simulations/baseAction/baseTestActions.scala:11: value TheObjectMapper is not amember of object io.gatling.core.json.Jackson
19:29:20.960 [ERROR] i.g.c.ZincCompiler$ - import io.gatling.core.json.Jackson.TheObjectMapper
19:29:20.961 [ERROR] i.g.c.ZincCompiler$ - ^
19:29:20.999 [ERROR] i.g.c.ZincCompiler$ - /Users/kang.hua/Downloads/gatling_API/user-files/simulations/baseAction/baseTestActions.scala:14: not found: value TheObjectMapper
19:29:21.000 [ERROR] i.g.c.ZincCompiler$ - def toJsonString(str: String) = TheObjectMapper
19:29:21.000 [ERROR] i.g.c.ZincCompiler$ - ^
19:29:21.763 [ERROR] i.g.c.ZincCompiler$ - /Users/kang.hua/Downloads/gatling_API/user-files/simulations/baseAction/baseTestActions.scala:45: not found: value ELFileBody
19:29:21.763 [ERROR] i.g.c.ZincCompiler$ - .is(ELFileBody(expected_response).map(str => toJsonString(str))))
19:29:21.763 [ERROR] i.g.c.ZincCompiler$ - ^

在 2016年2月4日星期四 UTC-8下午2:46:21,Michał Woźniak写道: