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.

Miki
已提問 2 年前檢視次數 92 次
沒有答案

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南