Hi, I use wiremock to test my application as a gr...
# help
n
Hi, I use wiremock to test my application as a grpc server. I have an request which like '{"id":"cluster_p-platform-test1mars"}' and wish to transform this about by parsing id via '_' char and get the second part for testing. I use mapping json. How can i solve a parsing operation to my external get.json Input:
Copy code
{
  "id": "cluster_p-platform-test1mars"
}
Mapping json :
Copy code
{
  "request": {
    "method": "POST",
    "urlPath": "/kubernetes.Service/Get"
  },
  "response": {
    "status": 200,
    "headers": {
      "Content-Type": "application/grpc"
    },
    "transformers": [
      "response-template"
    ],
    "bodyFileName": "get.json"
  }
}
Output:
Copy code
{
    "payload": {
    	 "cluster": "p-platform-test1mars",    // spliting id with _ and get [1] of data
    }
}
t
If I understand correctly - that you want the output you specified to be your response body, you can use the
regexExtract
and
jsonPath
helpers e.g.
Copy code
{{#trim}}
{{regexExtract (jsonPath request.body '$.id') '(.+)_(.+)' 'parts'}}
{
    "payload": {
    	 "cluster": "{{parts.1}}",
    }
}
{{/trim}}
n
Hi Tom , You are great . Thanks for support ! I spent a day to find it . You solved the problem . Thanks
😁 1
m
Hi @Tom , I am also looking for the same solution but in my case the ID is a header so how to pass that header value to regexExtract ?