How can I stub application/json response without having to escape all the double quotes, i.e.:
I want to get rid off all of those escape chars in response.body contents:
{
"request": {
"method": "GET",
"url": "/some/thing"
},
"response": {
"status": 200,
"body": "{\"id\": \"1\", \"type\": \"something\"}",
"headers": {
"Content-Type": "application/json"
}
}
}
You can put the body in a separate file using bodyFilePath.
@tomakehurst How does that work precisely?
Like this?
{
"request": {
"method": "GET",
"url": "/some/thing"
},
"response": {
"status": 200,
"bodyFilePath": "path/to/file",
"headers": {
"Content-Type": "application/json"
}
}
}
I got it to work!
For the next person needing this: at least on wiremock 2.8 the property is actually called bodyFileName, not bodyFilePath.
I get away with :
"body": "{'id': '1', 'type': 'something'}", or
"body": '{ ... }'
You can always use jsonBody instead of body and have much cleaner code:
{
"request": {
"method": "GET",
"url": "/some/thing"
},
"response": {
"status": 200,
"jsonBody": {"id": "1", "type": "something"},
"headers": {
"Content-Type": "application/json"
}
}
}
Most helpful comment
You can always use
jsonBodyinstead ofbodyand have much cleaner code: