Search code examples
wiremockwiremock-standalone

Wiremock how to return value in response from the request when the request key has dot


I have a request body in json with some keys having dot (.) in the name. ( i.e. get John Doe)

{
  "details":{
  "full.name":"John Doe", 
  "age":30, 
  "city":"Boston"
  }
}

In the stub definition I have:

{
  "request":{
    "urlPath":"/path",
    "method":"ANY"
   },
  "response":{
     "body":"{{jsonbody response.body '$.details.[full.name]'}}"
  }
}

stub gets created but I get this error when I hit it:

Error 500 wiremock.com.google.common.util.concurrent.UncheckedException: wiremock.com.github.jknack.handlebars.HandlebarsException: inline@26d6cbba:1:3: count not find helper: 'jsonpath'....

I tried escaping [] around full.name with \ , ** and %5B%5D still no luck. What is the current syntax.

Wiremock 2.33


Solution

  • Got this working.

    jsonPath can work with both . notation and [] notation. Since here . is the part of keyname I used [] to avoid confusing wiremock. Following stub gives me desired result:

    {
      "request":{
        "urlPath":"/path",
        "method":"ANY"
       },
      "response":{
         "body":"{{jsonbody response.body \"$['details']['full.name']\"}}"
      }
    }