cancel
Showing results for 
Search instead for 
Did you mean: 

How to use JSON To XML to remove Attribute

tholan96
Discoverer
0 Kudos
393

Hi,

I am looking to convert below JSON to XML and use it in mapping and send to SFDC. But I am unable to convert due to Attributes coming in the response from S4.

{

"@odata.context": "$metadata#QualityNotification",

"@odata.metadataEtag": "W/\"20231011103819\"",

"value": [

{

"@odata.etag": "W/\"SADL-020230802142305C~20230802142305\"",

"QualityNotification": "200000000",

}

]

}

Could you help me and guide how I can remove the attributes and pass only the required values?

Accepted Solutions (0)

Answers (3)

Answers (3)

Sriprasadsbhat
Active Contributor
0 Kudos

Please upvote or accept the answer and close the thread.

Regards,

Sri

Sriprasadsbhat
Active Contributor
0 Kudos

Below should work.

Also purpose of sharing these references to reuse bit of it and modify as per your requirement.

import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
import groovy.json.JsonSlurper;
import groovy.json.JsonOutput;
import groovy.json.*;
    
    def Message processData(Message message)
	{
        println "You can print and see the result in the console!"
        //Body 
        def body = message.getBody(String);
        def jsonSlurper = new JsonSlurper();
        def list = jsonSlurper.parseText(body);    
  
        list.remove('@odata.context');       
        list.remove('@odata.metadataEtag');
        list.value.each{
            it.remove('@odata.etag'); 
        }

        def jsonOP = JsonOutput.toJson(list)
        message.setBody(jsonOP);
        return message;
    }
    

Regards,

Sri

tholan96
Discoverer
0 Kudos

Thanks a lot Shiva, Will modify it based on my requirement.

Sriprasadsbhat
Active Contributor
0 Kudos
tholan96
Discoverer
0 Kudos

Hi Shivaram,

I tried But I am unable to remove @odata.context and @odata.metadataflag.

even though tried using jsonObject.remove("@odata.context")

jsonObject.remove("@odata.metadataEtag") but still I am unable to remove them.