cancel
Showing results for 
Search instead for 
Did you mean: 

Changing keys of an Object

aditya_gupta41
Contributor

Hello Experts,

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

INPUT:

[
  {
    "soapenv:Envelope": {
      "@xmlns:soapenv": "http://schemas.xmlsoap.org/soap/envelope/",
      "@xmlns:xsd": "http://www.w3.org/2001/XMLSchema",
      "@xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance",
      "soapenv:Body": {
        "ns1:MT_SWE_FI_PEGA_ABAON": {
          "@xmlns:ns1": "http://xyz.com",
          "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

1 ACCEPTED SOLUTION

JensDeveloper
Contributor II

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
$[‘soapenv:Envelope’][‘soapenv:Body’][‘ns1:MT_SWE_FI_PEGA_ABAON’]

The result:
image

Regards

Jens

View solution in original post

2 REPLIES 2

JensDeveloper
Contributor II

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
$[‘soapenv:Envelope’][‘soapenv:Body’][‘ns1:MT_SWE_FI_PEGA_ABAON’]

The result:
image

Regards

Jens

Thanks Jens. It worked