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
gefragt vor 2 Jahren92 Aufrufe
Keine Antworten

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen