# Compare bodyString to simple String

**URL:** <https://community.gatling.io/t/compare-bodystring-to-simple-string/3203>\
**Category:** Gatling (Open-Source)\
**Created:** [August 20, 2016, 12:19pm UTC](https://community.gatling.io/t/compare-bodystring-to-simple-string/3203 "2016-08-20T12:19:24Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andrei\_Proskurin](https://avatars.discourse-cdn.com/v4/letter/a/977dab/32.png) [@Andrei\_Proskurin](https://community.gatling.io/u/Andrei_Proskurin)\
**Post date:** [August 20, 2016, 12:19pm UTC](https://community.gatling.io/t/compare-bodystring-to-simple-string/3203/1 "2016-08-20T12:19:24Z")

</div>

I need to insert a check to compare response bodies. If I declare it like this:

`check(bodyString.is(expectedResponseBody))`  
then I get the following error:

`bodyString.find.is({"jsonrpc":"2.0","id":123456,"result":{"message":"OK"}}), but actually found {"jsonrpc":"2.0","id":123456,"result":{"message":"OK"}}`

I suppose the problem is different types, because the byte values are different. Should I use transform? If so, how should I do this? Thanks for your attention.

---

<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:** [August 20, 2016, 2:00pm UTC](https://community.gatling.io/t/compare-bodystring-to-simple-string/3203/2 "2016-08-20T14:00:07Z")

</div>

Weird.  
Are you sure you don’t have a different character somewhere, such as Linux vs Windows line feeds and such?  
Could you please provide a reproducer?

---

<div class="post-metadata">

**Author:** ![Andrei\_Proskurin](https://avatars.discourse-cdn.com/v4/letter/a/977dab/32.png) [@Andrei\_Proskurin](https://community.gatling.io/u/Andrei_Proskurin)\
**Post date:** [August 21, 2016, 4:54pm UTC](https://community.gatling.io/t/compare-bodystring-to-simple-string/3203/3 "2016-08-21T16:54:45Z")

</div>

I tried different options and what did the trick is:

`  
check(bodyString.transform(string =\> string.trim).is(expectedResponseBody))

`

Can it be the case, that leading and trailing are not being logged?

---

<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:** [August 21, 2016, 5:05pm UTC](https://community.gatling.io/t/compare-bodystring-to-simple-string/3203/4 "2016-08-21T17:05:23Z")

</div>

Could you compare the lengths?  
Or provide a reproducer?

---

<div class="post-metadata">

**Author:** ![Andrei\_Proskurin](https://avatars.discourse-cdn.com/v4/letter/a/977dab/32.png) [@Andrei\_Proskurin](https://community.gatling.io/u/Andrei_Proskurin)\
**Post date:** [August 22, 2016, 6:18am UTC](https://community.gatling.io/t/compare-bodystring-to-simple-string/3203/5 "2016-08-22T06:18:13Z")

</div>

I unfortunately cannot provide a reproducer. The response is coming from our internal server. I tried to compare lengths though and got the following results:

`  
09:15:20.826 - Expected response is: {“jsonrpc”:“2.0”,“id”:123456,“result”:{“message”:“OK”}}: Length: 55

09:15:20.826 - BodyString response is: {“jsonrpc”:“2.0”,“id”:123456,“result”:{“message”:“OK”}}  
: Length: 56

`

So there was apparently a ‘\n’ character in the end, but it didn’t display in the 'bodyString.find.is(…) block.

---

<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:** [August 22, 2016, 6:47am UTC](https://community.gatling.io/t/compare-bodystring-to-simple-string/3203/6 "2016-08-22T06:47:47Z")

</div>

In your original message, you copied:

`bodyString.find.is({"jsonrpc":"2.0","id":123456,"result":{"message":"OK"}}), but actually found {"jsonrpc":"2.0","id":123456,"result":{"message":"OK"}}`

Are you sure you didn’t get an additional line feed after this line?

---

<div class="post-metadata">

**Author:** ![Andrei\_Proskurin](https://avatars.discourse-cdn.com/v4/letter/a/977dab/32.png) [@Andrei\_Proskurin](https://community.gatling.io/u/Andrei_Proskurin)\
**Post date:** [August 22, 2016, 7:10am UTC](https://community.gatling.io/t/compare-bodystring-to-simple-string/3203/7 "2016-08-22T07:10:17Z")

</div>

Yes, you are right. The whole message is:

`

09:55:46.184 [TRACE] i.g.h.a.ResponseProcessor -

> > > > > > > > > > > > > > > > > > > > > > > > > >

Request:  
deleteAccount: should succeed: KO bodyString.find.transform.is({“jsonrpc”:“2.0”,“id”:123456,“result”:{“message”:“OK”}}), but actually found {“jsonrpc”:“2.0”,“id”:123456,“result”:{“message”:“OK”}}
