Forum Discussion

SankarB's avatar
SankarB
Occasional Contributor
8 years ago

How to get the item count

Hi,   How do i get the count of items for the below JSON response    { "@type": "com.a.common.model.dto.CollectionDTO", "id": null, "items": [ { "@type": "com.a.b.client.model.dto.Asset", ...
  • nmrao's avatar
    8 years ago

    Add Script Assertion with below code:

     

    assert context.response, "Response is empty or null"
    
    def json = new groovy.json.JsonSlurper().parseText(context.response)
    log.info json.items.size()
    
  • groovyguy's avatar
    groovyguy
    8 years ago

    Try replacing [i] with [$i] to reference the value as a number instead of a string.