import groovy.json.JsonOutput;
def parser = new groovy.json.JsonSlurper();
def jsonResp = parser.parseText(responseBodyTextToClient);
static String mask(String input, int exceptFirst, int exceptLast) {
String regex="(?<=.{" + exceptFirst + "}).(?=.{"+ exceptLast + "})";
return input.replaceAll(regex, "*");
}
for(Object data in jsonResp.data) {
data.NAME = mask(data.NAME,1,2)
data.SURNAME = mask(data.SURNAME,1,2)
data.PHONENUMBER= mask(data.PHONENUMBER,1,2)
}
responseBodyTextToClient=JsonOutput.prettyPrint(JsonOutput.toJson(jsonResp))
CODE