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
asked 2 years ago92 views
No Answers

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions