https://linen.dev logo
#general
Title
# general
j

Joao Victor F. Carvalho

01/09/2024, 6:01 PM
Hello folks, I'm knew to wiremock and I have a small issue doubt: I'm creating a mock this way, however the body returned is in string format even having the header content-type as json. I'm attaching mock creation and response received, can someone advice?
l

Lee Turner

01/09/2024, 6:08 PM
Hi, I think this is because you have created the response body as a string. If you use the
body
element for the response you have to wrap it in quotes and escape the string:
Copy code
"body": "{\"foo\": \"bar\"}"
For the
json
responses the
jsonBody
is more convenient because you don't have to do that:
Copy code
"jsonBody": {"foo": "bar"}
This section of the docs explains it a little more - https://wiremock.org/docs/stubbing/#specifying-the-response-body
j

Joao Victor F. Carvalho

01/09/2024, 8:35 PM
thanks for sharing @Lee Turner, I'm taking a look into "arbitrary_json":, didn't have success yet but need to try more.
l

Lee Turner

01/09/2024, 8:37 PM
No worries. I think the arbitary_json was just an example in the docs. Nothing special for what you are trying to do.
I think you should be able to just remove the quote from around your body and un-escape all the quotes.
j

Joao Victor F. Carvalho

01/09/2024, 8:44 PM
omg, is it? lol. anyways, I tried now un-escaped. It didn't work 😞
l

Lee Turner

01/09/2024, 8:46 PM
Can you share your full mapping file so I can see what is happening ?
j

Joao Victor F. Carvalho

01/09/2024, 8:46 PM
let me clean up some stuff and reproduce, I will share shortly
@Lee Turner, I reviewed my mapping, and I was doing something wrong, I fixed it and now its working and I know I don't need to escape when using. Thanks
l

Lee Turner

01/09/2024, 9:19 PM
Awesome. Glad you got it working.
🙌 1