# JSON Feeder trouble (2.1.5)

**URL:** <https://community.gatling.io/t/json-feeder-trouble-2-1-5/2215>\
**Category:** Gatling (Open-Source)\
**Created:** [April 16, 2015, 3:32pm UTC](https://community.gatling.io/t/json-feeder-trouble-2-1-5/2215 "2015-04-16T15:32:38Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alexis\_Huard](https://avatars.discourse-cdn.com/v4/letter/a/c4cdca/32.png) [@Alexis\_Huard](https://community.gatling.io/u/Alexis_Huard)\
**Post date:** [April 16, 2015, 3:32pm UTC](https://community.gatling.io/t/json-feeder-trouble-2-1-5/2215/1 "2015-04-16T15:32:38Z")

</div>

Hi there,

Currently browsing through a couple of stress tools and gatling looks promising so far.

It does seem to fit one of my requirements, which is to spawn several _different_ users for a said test.

I found out that [Feeders](http://gatling.io/docs/2.1.5/session/feeder.html) might just do the job, but I have some problems implementing it. This is what I tried so far.

I attempt to have the following structure for my tests :

`  
class UserSignIn extends Simulation {  
val httpProtocol = http  
// […]

val feedUser = jsonFile(“users.json”)  
val scn = scenario(“User signing in”)  
.feed(feedUser.random)  
.exec(SignIn.signin, /\* A few more scenarios executing \*/, SignOut.signout)

setUp(  
scn.inject(  
atOnceUsers(20)  
)).protocols(httpProtocol)

object SignIn {  
// A few headers

val uri1 = “[https://some.domain](https://some.domain)”

val signin= exec(  
http(“sign\_in”)  
.post("/api/users/sign\_in")  
.headers(headers\_0)  
.body(/_…_/)  
.resource(  
// A few more calls  
)  
).pause(15)  
}

object SignOut {

// More cool stuff !

}  
}

`

My JSON file looks like this :

`  
[  
{  
“user”: {  
“login”: “”,  
“password”: “”,

 

// A few more parameters

 

}  
}, {  
// A couple more users  
}  
]  
`

 

I have no idea how to use the fed user in the _body_ part.  
Of course, it returned a 401 (but compiled !).  
I tried to add a couple _.queryParam()_ , as specified, which prevented my code to _compile_.

 

After messing around and reading stuff here and there, I decided to ask this Google Group.  
I also read this [article](https://ahlearns.wordpress.com/2014/01/16/gatling-stress-tool-example-simulation-with-a-circular-feed/), which was outdated (Gatling: 1.5.3), but decided to give it a try.

So I changed my feeder to use a tsv and used this body line :

`.body("${user}") .asJSON`

And re-arranged my JSON like this :

`  
user  
{{“user”:{“login”:"",“password”:""/_…_/}}  
{{“user”:/\* …_/}}  
{{“user”😕_ …\*/}}

 

`

 

This time, I got a different error message :

 

`

 

GATLING\_HOME is set to //gatling  
11:05:37.786 [ERROR] i.g.c.ZincCompiler$ - //gatling/user-files/simulations/user\_signin/user\_signin.scala:35: type mismatch;  
found : String("${user}")  
required: io.gatling.http.request.Body

 

`

 

I am kind of lost now… Anyone might giving me some advices ?

 

I hope I provided enough details about my situation.

 

Thanks,  
Alexis

---

<div class="post-metadata">

**Author:** ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)\
**Post date:** [April 16, 2015, 3:40pm UTC](https://community.gatling.io/t/json-feeder-trouble-2-1-5/2215/2 "2015-04-16T15:40:17Z")

</div>

Exactly what happens when reading some outdated random article instead of the official documentation 🙂

In Gatling 2, body takes a Body object, not a String:  
[http://gatling.io/docs/2.1.5/http/http\_request.html#request-body](http://gatling.io/docs/2.1.5/http/http_request.html#request-body)

---

<div class="post-metadata">

**Author:** ![Alexis\_Huard](https://avatars.discourse-cdn.com/v4/letter/a/c4cdca/32.png) [@Alexis\_Huard](https://community.gatling.io/u/Alexis_Huard)\
**Post date:** [April 16, 2015, 3:53pm UTC](https://community.gatling.io/t/json-feeder-trouble-2-1-5/2215/3 "2015-04-16T15:53:50Z")

</div>

Oh, but I have r_ead_ your documentation and I tried to use body(StringBody("${user}").asJSON which won’t work either.

It seems like a character escaping problem, because when I consult my log files, I can see the following :

`  
{user": {“login”: “”,“password”: “”,“remember\_me”: false,“language”: “fr”}}

`

The leading **"** as disappeared from my line, even if it is correctly written inside the file :

`

user  
{“user”: {“login”: “”,“password”: “”,“remember\_me”: false,“language”: “fr”}

`

But if I print the exact same line, with character escaping, inside the StringBody() function, it does work.

Character escaping parsing ? 🙂

---

<div class="post-metadata">

**Author:** ![Alexis\_Huard](https://avatars.discourse-cdn.com/v4/letter/a/c4cdca/32.png) [@Alexis\_Huard](https://community.gatling.io/u/Alexis_Huard)\
**Post date:** [April 16, 2015, 3:57pm UTC](https://community.gatling.io/t/json-feeder-trouble-2-1-5/2215/4 "2015-04-16T15:57:27Z")

</div>

Ok, I did put some character escaping in front of every **"** encountered and wrapped my JSON inside a string, which worked.

So, tsp seems to work. I might prefer sticking to my JSON files, as they are used in some other tests.

Any advices on how to use the JSON Feeder with my desired structure ?

---

<div class="post-metadata">

**Author:** ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)\
**Post date:** [April 16, 2015, 4:04pm UTC](https://community.gatling.io/t/json-feeder-trouble-2-1-5/2215/5 "2015-04-16T16:04:19Z")

</div>

> Ok, I did put some character escaping in front of every \*"\* encountered  
> and wrapped my JSON inside a string, which worked.
> 
> So, tsp seems to work. I might prefer sticking to my JSON files, as they  
> are used in some other tests.

Double quote is a special character in CSV and the likes.  
It's used to protect String values that might contain the same char used as  
separator.  
See rawSplit doc  
\<[http://gatling.io/docs/2.1.5/session/feeder.html#csv-feeders&gt;\](http://gatling.io/docs/2.1.5/session/feeder.html#csv-feeders&gt;%5C).

> Any advices on how to use the JSON Feeder with my desired structure ?

JsonFeeder is used for injecting DATA, ie, it's parsed into an object AST.  
If you want to convert back to JSON, you can use for example jsonStringify.  
See jsonStringify doc  
\<[http://gatling.io/docs/2.1.5/session/expression\_el.html#expression-language&gt](http://gatling.io/docs/2.1.5/session/expression_el.html#expression-language&gt);  
.

---

<div class="post-metadata">

**Author:** ![Vu\_Nguyen1](https://avatars.discourse-cdn.com/v4/letter/v/bbce88/32.png) [@Vu\_Nguyen1](https://community.gatling.io/u/Vu_Nguyen1)\
**Post date:** [April 16, 2015, 9:16pm UTC](https://community.gatling.io/t/json-feeder-trouble-2-1-5/2215/6 "2015-04-16T21:16:55Z")

</div>

Alexis,

Try triple quote to see if that works in your case:  
[http://gatling.io/docs/2.1.5/advanced\_tutorial.html?highlight=triple%20quote](http://gatling.io/docs/2.1.5/advanced_tutorial.html?highlight=triple%20quote)

.body(StringBody("""${user}""")).asJSON
