SK07
7 years agoContributor
Groupby using groovy
I want to display by groupby item and count the rate using groovy in ReadyAPI.(Like this: Item 12: Count(Rate) : 400
Json1 : {"prods": [{"Item":"11","rate": 100},{Item":"12","rate":200},{Item":"12","rate":200}]}.
SK07,
Here you go:
https://github.com/nmrao/soapUIGroovyScripts/blob/master/groovy/json/JsonGroupByAndSum.groovydef json = new groovy.json.JsonSlurper().parseText(jsonString) json.prods.groupBy{it.Item}.each { key, value -> log.info "Item : ${key}, Sum (of rate): ${value.sum{it.rate}}" }