Forum Discussion
TNeuschwanger
Champion Level 2
Hello User999
Here is an attempt at your solution. Drop this into a groovy test step to exercise it and add a "Properties" test step to catch the resultant new json. Hack it up as desired. There might be portions that are helpful to your final resolution...
import groovy.json.JsonSlurper;
import groovy.json.JsonOutput;
log.info 'Test Step "' + testRunner.runContext.currentStep.name + '" start...';
log.info "";
// embellished some sample json I had laying around...
def String jsonStr = """
[
{
"createDate": "2004-01-01T00:00:00",
"endDate": null,
"lastUpdateDate": null,
"lastUpdateUser": null,
"instanceCode": "CLAIM",
"roleCode": "ALL",
"roleName": "All",
"newBusinessRatingReferenceId": "string",
"offerOriginChannelEntCd": "string",
"offerOriginSubChannelEntCd": "string",
"originalOfferOriginChannelEntCd": "string",
"originalOfferOriginSubChannelEntCd": "string",
"ratingReferenceId": "string",
"schemaVersionNbr": "string",
"sourceSystemEntCd": "string",
"transactionEffDtTimeStr": "string",
"transactionProcessedDtTimeStr": "string",
"transactionSubEntCd": "string",
"roleType": "DEVELOPER"
},
{
"createDate": "2004-01-01T00:00:00",
"endDate": "2021-01-12T00:00:00",
"lastUpdateDate": null,
"lastUpdateUser": null,
"instanceCode": "CLAIM",
"roleCode": "BACK_OFFICE",
"roleName": "Back Office",
"newBusinessRatingReferenceId": "string",
"offerOriginChannelEntCd": "string",
"offerOriginSubChannelEntCd": "string",
"originalOfferOriginChannelEntCd": "string",
"originalOfferOriginSubChannelEntCd": "string",
"ratingReferenceId": "string",
"schemaVersionNbr": "string",
"sourceSystemEntCd": "string",
"transactionEffDtTimeStr": "string",
"transactionProcessedDtTimeStr": "string",
"transactionSubEntCd": "string",
"roleType": "WEB"
}
]
""";
def jsonSlurper = new JsonSlurper();
def jsonObj = jsonSlurper.parseText(jsonStr);
log.info "jsonObj=$jsonObj";
// I don't know the extent of the depth of your actual JSON, so the sample I used contains two groups... You might have to
// eliminate a depth on your actual (or add more).
jsonObj.each { depth ->
depth.each { element ->
log.info "elementBefore=${element.value}";
if (element.value == 'string') {
randomString = org.apache.commons.lang.RandomStringUtils.random(6, true, true);
element.value = randomString;
};
log.info " elementAfter=${element.value}";
};
};
jsonNewStr = JsonOutput.toJson(jsonObj);
log.info "jsonNewStr=$jsonNewStr";
// make sure to have a "Properties" test step to have a landing area for the resultant new json content.
testRunner.testCase.testSteps['Properties'].setPropertyValue('jsonNewStr', jsonNewStr);
// The resultant json will be something like...
//[
// {
// "createDate": "2004-01-01T00:00:00",
// "endDate": null,
// "instanceCode": "CLAIM",
// "lastUpdateDate": null,
// "lastUpdateUser": null,
// "newBusinessRatingReferenceId": "M7MzVq",
// "offerOriginChannelEntCd": "oLU3Qe",
// "offerOriginSubChannelEntCd": "QWV5O8",
// "originalOfferOriginChannelEntCd": "7ydvd3",
// "originalOfferOriginSubChannelEntCd": "OlHycp",
// "ratingReferenceId": "DgEiM5",
// "roleCode": "ALL",
// "roleName": "All",
// "roleType": "DEVELOPER",
// "schemaVersionNbr": "R8w1WO",
// "sourceSystemEntCd": "KuPtvJ",
// "transactionEffDtTimeStr": "ujlqUr",
// "transactionProcessedDtTimeStr": "UdD7se",
// "transactionSubEntCd": "Sn8lRS"
// },
// {
// "createDate": "2004-01-01T00:00:00",
// "endDate": "2021-01-12T00:00:00",
// "instanceCode": "CLAIM",
// "lastUpdateDate": null,
// "lastUpdateUser": null,
// "newBusinessRatingReferenceId": "6LUM3g",
// "offerOriginChannelEntCd": "71CyqS",
// "offerOriginSubChannelEntCd": "WVDGbU",
// "originalOfferOriginChannelEntCd": "zqOwZD",
// "originalOfferOriginSubChannelEntCd": "fiUk22",
// "ratingReferenceId": "ow6Sjg",
// "roleCode": "BACK_OFFICE",
// "roleName": "Back Office",
// "roleType": "WEB",
// "schemaVersionNbr": "vGwmld",
// "sourceSystemEntCd": "nvdMQx",
// "transactionEffDtTimeStr": "3vQ6L6",
// "transactionProcessedDtTimeStr": "PrxZsV",
// "transactionSubEntCd": "84dzvX"
// }
//]
log.info "";
log.info 'Test Step "' + testRunner.runContext.currentStep.name + '" done...';
Regards,
Todd