Я пытаюсь удалить пустые элементы, т.е. двойные кавычки из массива, но я не уверен, как перебрать массив json. Ниже мой json
{
"body": {
"newId":"value1"
},
"header": {
"appId": "someVal",
"pricingSchedule": [
"price1",
"price2",
"price3",
"",
"",
""
]
},
"trail": {
"pageSize": "50"
}
}
, что я хочу сделать, находится в header
, я хочу перебрать массив pricingSchedule
и удалить пустые элементы, и если в массиве нет элементов, то я хочу просто хранить пустой массив, а не удалять его.
Ниже приведен мой попытанный код -
def request = new groovy.json.JsonSlurper().parseText(sampler.getArguments().getArgument(0).getValue())
def newRequest = evaluate(request.inspect())
request.body.each { entry ->
if (entry.getValue().equals('') || entry.getValue().equals([''])) {
newRequest.body.remove(entry.getKey())
}
}
request.header.each{ entry ->
// String key=entry.getKey().equals("pricingSchedule")
entry.getKey().equals("pricingSchedule").each{ entry1 ->
log.info(entry1) //This does not print anything and gives me error
}
}
def arguments = new org.apache.jmeter.config.Arguments()
sampler.setArguments(arguments)
sampler.addNonEncodedArgument('', new groovy.json.JsonBuilder(newRequest).toPrettyString(), '')
sampler.setPostBodyRaw(true)