Convert VTL object to JSON in API gateway

0

I'm trying to transform the response for API gateway, the problem is that the response is relative dynamic, and I need to make a transformation on a specific attribute.

Below examples of possible responses

{
  "results": {
    "name1": [
      {
        "phoneNumber": "000000000",
        "attr1": "foo"
      },
      {
        "phoneNumber": "000000001",
        "attr1": "foo1"
      }
    ]
  }
}
{
  "results": {
    "name2": [
      {
        "phoneNumber": "\"000000000\"",
        "attr4": {
          "foo1": [
            "abc"
          ],
          "foo2": true
        }
      },
      {
        "phoneNumber": "\"000000005\"",
        "attr4": {
          "foo1": [
            "bar"
          ],
          "foo2": false
        }
      }
    ]
  }
}

The attribute that I want to change is "phoneNumber" that is the same for any response and the location is always $.results..phoneNumber, and I need to JSON parse it.

I could convert the response in VTL object with $util.path('$') but then I would need to recreate the entire response, and because it's dynamic it's very difficult, so I was wondering if there is something easier and convert the VTL to JSON, or otherwise modify the object directly without convert to VTL object.

답변 없음

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠