# Using feeders to construct a StringBody (2.0.0-M3a)

**URL:** <https://community.gatling.io/t/using-feeders-to-construct-a-stringbody-2-0-0-m3a/627>\
**Category:** Gatling (Open-Source)\
**Created:** [October 21, 2013, 8:19pm UTC](https://community.gatling.io/t/using-feeders-to-construct-a-stringbody-2-0-0-m3a/627 "2013-10-21T20:19:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hank](https://avatars.discourse-cdn.com/v4/letter/h/f475e1/32.png) [@Hank](https://community.gatling.io/u/Hank)\
**Post date:** [October 21, 2013, 8:19pm UTC](https://community.gatling.io/t/using-feeders-to-construct-a-stringbody-2-0-0-m3a/627/1 "2013-10-21T20:19:54Z")

</div>

Okay, I’ve got another feeder/http POST body question. Thank you for all of your help so far - Gatling is an awesome tool, and I feel like I’m so close to getting it to work for our project.

I’m continuing to work on my registration load test, and now I’m running into the following issue when attempting to use a feeder to generate my JSON POST body - some lines don’t seem to be correctly handling double quotes in my CSV file. (Of three requests, one worked, two mysteriously didn’t.)

Relevant script pieces:  
val userData = csv(“test.csv”).queue

val httpConf = http.baseURL(“[http://myappurl.com/api](http://myappurl.com/api)”)

val scn = scenario(“Register user”)  
.feed(userData)  
.exec(  
http(“POST registration”)  
.post("/user/register")  
.headers(headers\_1)  
.body(StringBody("""{“username”:${username}, “email”:${email}, “imei”:${imei}, “gcmId”:${gcmId}, “age”:${age},“albumSelection”:${albumSelection},“latitude”:${latitude},“longitude”:${longitude},“emailOptIn”:${emailOptIn},“termsOptIn”:${termsOptIn} }""")))

My CSV file looks like this:

username,emailOptIn,albumSelection,termsOptIn,age,gcmId,longitude,latitude,imei,email  
““[tester7105408553"",true,"“clean”",false,"“62"”,"“7105408553"”,0,45,"“999997105408553"”,""tester7105408553@mailinator.com](mailto:tester7105408553%22%22,true,%22%22clean%22%22,false,%22%2262%22%22,%22%227105408553%22%22,0,45,%22%22999997105408553%22%22,%22%22tester7105408553@mailinator.com)””  
““[tester7317165156"",true,"“clean”",true,"“59"”,"“7317165156"”,176,65,"“999997317165156"”,""tester7317165156@mailinator.com](mailto:tester7317165156%22%22,true,%22%22clean%22%22,true,%22%2259%22%22,%22%227317165156%22%22,176,65,%22%22999997317165156%22%22,%22%22tester7317165156@mailinator.com)””  
““[tester6271383680"",true,"“explicit”",true,"“37"”,"“6271383680"”,-42,-82,"“999996271383680"”,""tester6271383680@mailinator.com](mailto:tester6271383680%22%22,true,%22%22explicit%22%22,true,%22%2237%22%22,%22%226271383680%22%22,-42,-82,%22%22999996271383680%22%22,%22%22tester6271383680@mailinator.com)””

It seems like everything is correct there, but when I run with logging turned on, I see the following messages:

Session:  
Session(Register user,1,Map(latitude → 65, email → “[tester7317165156@mailinator.com](mailto:tester7317165156@mailinator.com)”, username → tester7317165156", imei → “999997317165156”, age → “59”, longitude → 176, termsOptIn → true, emailOptIn → true, gcmId → “7317165156”, albumSelection → “clean”),1382385464346,0,List(),List(KO),List(),List())

---

<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:** [October 21, 2013, 8:34pm UTC](https://community.gatling.io/t/using-feeders-to-construct-a-stringbody-2-0-0-m3a/627/2 "2013-10-21T20:34:56Z")

</div>

Hi,

Except if gmail did something funny with your original message, it seems your csv file is still messed up: double quotes inside a field have to be escape, and the whole field has to be surrounded with double quotes:

- "“tester7105408553"” =\> bad
- "“tester7105408553"” =\> good  
We use opencsv underneath, and it silently does weird stuff with malformed csv.

Anyway, why don’t you handle JSON string value quotes inside your JSON template?

You csv file would look like:

username,emailOptIn,albumSelection,termsOptIn,age,gcmId,longitude,latitude,imei,email  
tester7105408553,true,clean,false,62,7105408553,0,45,999997105408553,[tester7105408553@mailinator.com](mailto:tester7105408553@mailinator.com)

and your template like this:  
“”"{  
“username”:"${username}",  
“email”:"${email}",  
“imei”:"${imei}",  
“gcmId”:"${gcmId}",  
“age”:"${age}",  
“albumSelection”:"${albumSelection}",  
“latitude”:${latitude},  
“longitude”:${longitude},  
“emailOptIn”:${emailOptIn},  
“termsOptIn”:${termsOptIn}  
}"""

WDYT?

---

<div class="post-metadata">

**Author:** ![Hank](https://avatars.discourse-cdn.com/v4/letter/h/f475e1/32.png) [@Hank](https://community.gatling.io/u/Hank)\
**Post date:** [October 21, 2013, 10:32pm UTC](https://community.gatling.io/t/using-feeders-to-construct-a-stringbody-2-0-0-m3a/627/3 "2013-10-21T22:32:29Z")

</div>

That totally did the trick - I based the “double double quotes” off of some random CSV documentation I found, but your solution is better and more elegant, and works, to boot.

Thanks again for the prompt responses, much appreciated.

Thanks,  
Hank

---

<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:** [October 22, 2013, 7:16am UTC](https://community.gatling.io/t/using-feeders-to-construct-a-stringbody-2-0-0-m3a/627/4 "2013-10-22T07:16:16Z")

</div>

Was glad to help 🙂

Have fun!
