1

Is there any way to dynamically include JSON from the request body in the response?

Input Request

{
   "id":"1234",
   "message":"{\"key\":\"value\"}"
}

Expected Output

{
  "status":"CREATED",
  "id":"1234",
  "message":"{\"key\":\"value\"}"
}

The message and id fields are dynamic and need to be picked from the request.

I have tried the below mapping to dynamically load the response from the request but \" inside message json is converted to "

{
  "request": {
    "method": "POST",
    "urlPath": "/test"
  },
  "response": {
    "status": 200,
    "transformers": [
      "response-template"
    ],
    "jsonBody": {
      "status": "CREATED",
      "id": "{{jsonPath request.body '$.id'}}",
      "message": "{{jsonPath request.body '$.message'}}"
    }
  }
}

This returns message as {"key":"value"}.

Even, I have tried changing the mapping to {{{jsonPath request.body '$.message'}}}. But this messes up the whole response json and message value is being returned as "{"key":"value"}" without escape characters.

I'm looking for suggestions to map message dynamically. Thanks in advance.

Naveen Kumar
  • 75
  • 1
  • 7

0 Answers0