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.

Nessuna risposta

Accesso non effettuato. Accedi per postare una risposta.

Una buona risposta soddisfa chiaramente la domanda, fornisce un feedback costruttivo e incoraggia la crescita professionale del richiedente.

Linee guida per rispondere alle domande