Remove dummy fields from Json:
Groovy script:
import com.sap.gateway.ip.core.customdev.util.Message;
import groovy.json.JsonSlurper
import groovy.json.JsonOutput
def Message processData(Message message){
def body =message.getBody(java.lang.String) as String
def jsonParser =new JsonSlurper()
def jsonObject = jsonParser.parseText(body)
def rem = []
for(i=0;i<=20;i++){
def toseries = "dummy${i}"
rem << toseries
}
println rem.size()
def toRemove = rem
//def toRemove =["dummy0","dummy1"]
println toRemove
toRemove.each { field ->
jsonObject.remove(field.toString())
message.setBody(JsonOutput.toJson(jsonObject))}
return message;
}
No comments:
Post a Comment