import com.jayway.jsonpath.JsonPath
def path = vars.get("BaseFilePath") + "/" + vars.get("FhirVersion") + "/Get/Patient/";
def newLine = System.getProperty('line.separator')
def response = prev.getResponseDataAsString()
//address
def addressCSV = new File(path + 'address.csv')
def addressList = []
def addressCityCSV = new File(path + 'address-city.csv')
def cityList = []
def addressCountryCSV = new File(path + 'address-country.csv')
def countryList = []
def addressPostalCodeCSV = new File(path + 'address-postalcode.csv')
def postalCodeList = []
def addressStateCSV = new File(path + 'address-state.csv')
def stateList = []
def addressArray = JsonPath.read(response, '$..address')
addressArray.each { eachAddress ->
eachAddress.each { subAddress ->
subAddress.get('line').each { line ->
addressList.add(line)
}
cityList.add(subAddress.get('city'))
stateList.add(subAddress.get('state'))
postalCodeList.add(subAddress.get('postalCode'))
countryList(subAddress.get('country'))
}
addressList.unique().each { address ->
addressCSV << address << newLine
}
cityList.unique().each { city ->
addressCityCSV << city << newLine
}
countryList.unique().each { country ->
addressCountryCSV << country << newLine
}
postalCodeList.unique().each { postalCode ->
addressPostalCodeCSV << postalCode << newLine
}
stateList.unique().each { state ->
addressStateCSV << state << newLine
}
}
I wrote this scirpt in JSR223 post processor of jmeter, to extract data from json response, addressList, cityList and other lists contain duplicate elements so i wanted to remove the duplicates and push unique values into files. But this code is not working. Can someone help me in fixing this