cancel
Showing results for 
Search instead for 
Did you mean: 

removing the double quotes on the value of string field

0 Kudos

Dear All,

I'm converting payload XML to JSON using a standard converter.

The field "rows" is an array which should be generated like this "rows": [] when there are no values.

But the output from converter is "rows": [" "]
How can we remove these double quotes inside these brackets? The requirement is to change a array string element into array integer element. i.e. removing the double quotes on the value of string field.

I tried with the code below, but it did not work.
import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;def Message processData(Message message) { //Body def body = message.getBody(String) as String; message.setBody(body.replaceAll("[""]","[]")); return message;}

Best Regards

Revathi

View Entire Topic
markangelo_dihiansan
Active Contributor
0 Kudos

Hello,

You need to escape both the square brackets [] and double quotes " when using replaceAll since they are treated

as a regex statement. Both statements below should work

String sample = """"rows":[" "],\n"rows1":[" "]\n"""
println("Replace: "+sample.replace('[" "]','[]'))
println("ReplaceAll: "+sample.replaceAll('\\[\" \"\\]','[]')) 

Hope this helps,
Mark