https://linen.dev logo
#help
Title
# help
n

Nebi Volkan Ünlenen

02/16/2024, 7:17 AM
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

Tom

02/16/2024, 9:53 AM
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

Nebi Volkan Ünlenen

02/16/2024, 11:16 AM
Hi Tom , You are great . Thanks for support ! I spent a day to find it . You solved the problem . Thanks
😁 1
18 Views