Changing keys of an Object

Hello Experts,

I have a requirement where I need to change the value of one single key in an object.


    "soapenv:Envelope": {
      "@xmlns:soapenv": "",
      "@xmlns:xsd": "",
      "@xmlns:xsi": "",
      "soapenv:Body": {
        "ns1:MT_SWE_FI_PEGA_ABAON": {
          "@xmlns:ns1": "",
          "SYSTEMID": "AB1",
          "CLIENT": "090",
          "INPUT": {
            "S_BUKRS": "00",
            "S_ANLN1": "12345678",
            "S_ANLN2": "0000",
            "S_ZUGDT": "2022-06-20",
            "ERLBT": "100"

Here I just need to change key ‘CLIENT’ to ‘CLIENTID’.

Thanks in Advance

Hi @aditya.gupta41

you should use the function mapKeys in a mapper snap to get the key value and rename it.

Inside the mapper snap you should use this expression:
$[‘soapenv:Envelope’][‘soapenv:Body’][‘ns1:MT_SWE_FI_PEGA_ABAON’].mapKeys((value, key) => key == “CLIENT” ? “CLIENTID” : key)

This expression will first check every key if it equals the value “CLIENT” and if true it will rename it to whatever you want to rename it to. If false the key name is not changed

And give as target path the path of the original one until the object that contains CLIENT

The result:



Thanks Jens. It worked

1 Like