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