Hello folks, I'm knew to wiremock and I have a sma...
# general
j
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
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
thanks for sharing @Lee Turner, I'm taking a look into "arbitrary_json":, didn't have success yet but need to try more.
l
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
omg, is it? lol. anyways, I tried now un-escaped. It didn't work 😞
l
Can you share your full mapping file so I can see what is happening ?
j
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
Awesome. Glad you got it working.
🙌 1