# How to verify a specific value in a huge JSON array?

**URL:** <https://forum.katalon.com/t/how-to-verify-a-specific-value-in-a-huge-json-array/191556>\
**Category:** API Testing\
**Created:** [June 7, 2026, 3:55pm UTC](https://forum.katalon.com/t/how-to-verify-a-specific-value-in-a-huge-json-array/191556 "2026-06-07T15:55:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![qurzunta.kaab](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/qurzunta.kaab/32/31470_2.png) [@qurzunta.kaab](https://forum.katalon.com/u/qurzunta.kaab)\
**Post date:** [June 7, 2026, 3:55pm UTC](https://forum.katalon.com/t/how-to-verify-a-specific-value-in-a-huge-json-array/191556/1 "2026-06-07T15:55:02Z")

</div>

Here is how i did it. Is there any better way

Custom Keyword

```auto
package com.api.helpers

import com.kms.katalon.core.annotation.Keyword
import com.kms.katalon.core.testobject.ResponseObject
import com.kms.katalon.core.util.KeywordUtil
import groovy.json.JsonSlurper

public class ResponseVerifier {

	/**
	 * Verifies if a specific value exists within a JSON array attribute.
	 * @param response The ResponseObject returned from your API call.
	 * @param jsonPathElement The dot-notation path to the element containing the array (e.g., 'orders.status')
	 * @param expectedValue The value you are searching for (e.g., 'Invoiced')
	 * @return boolean true if found, false otherwise
	 */
	@Keyword
	def static boolean verifyValueExistsInArray(ResponseObject response, String jsonPathElement, String expectedValue) {
		try {
			// 1. Parse the raw response text into a Groovy object
			JsonSlurper slurper = new JsonSlurper()
			def jsonResponseBody = slurper.parseText(response.getResponseBodyContent())
			
			// 2. Use Groovy's GPath (similar to JsonPath) to collect the values
			// evaluation safely navigates nested maps/lists
			def actualValues = jsonResponseBody."${jsonPathElement}"
			
			// 3. Check if the value exists in the extracted collection
			if (actualValues != null && actualValues.contains(expectedValue)) {
				KeywordUtil.logInfo("Success! Found '${expectedValue}' in the array.")
				return true
			} else {
				KeywordUtil.markFailed("Failure! '${expectedValue}' was not found in the array.")
				return false
			}
		} catch (Exception e) {
			KeywordUtil.markFailed("An error occurred while parsing the JSON: " + e.getMessage())
			return false
		}
	}
}

```

####

---

<div class="post-metadata">

**Author:** ![ss1512](https://avatars.discourse-cdn.com/v4/letter/s/f04885/32.png) [@ss1512](https://forum.katalon.com/u/ss1512)\
**Post date:** [June 8, 2026, 4:51pm UTC](https://forum.katalon.com/t/how-to-verify-a-specific-value-in-a-huge-json-array/191556/2 "2026-06-08T16:51:36Z")

</div>

@qurzunta.kaab I think you can try this,

```auto
`@Keyword
static boolean verifyValueExistsInArray(
        ResponseObject response,
        String jsonPathElement,
        String expectedValue) {
    try {
        def json = new JsonSlurper().parseText(response.getResponseBodyContent())
        def actualValues = jsonPathElement.split('\\.').inject(json) { node, key ->
            node instanceof List ? node.collect { it[key] }.flatten() : node?[key]
        }

        if (actualValues == null) {
            KeywordUtil.markFailed("Path '${jsonPathElement}' resolved to null or does not exist.")
            return false
        }

        def valueList = actualValues instanceof List ? actualValues : [actualValues]

        if (valueList.contains(expectedValue)) {
            KeywordUtil.logInfo("Found '${expectedValue}' at '${jsonPathElement}'.")
            return true
        } else {
            KeywordUtil.markFailed(
                "'${expectedValue}' not found at '${jsonPathElement}'. " +
                "Actual values: ${valueList.take(10)}" // cap output for huge arrays
            )
            return false
        }
    } catch (Exception e) {
        KeywordUtil.markFailed("JSON parsing/traversal error: ${e.getMessage()}")
        return false
    }
}

```

---

<div class="post-metadata">

**Author:** ![sneha.sajeev](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/sneha.sajeev/32/29015_2.png) [@sneha.sajeev](https://forum.katalon.com/u/sneha.sajeev)\
**Post date:** [June 8, 2026, 4:56pm UTC](https://forum.katalon.com/t/how-to-verify-a-specific-value-in-a-huge-json-array/191556/3 "2026-06-08T16:56:21Z")

</div>

@qurzunta.kaab you can use Katalon’s built-in **`WS.verifyElementsCount`** or simply parse and use Groovy’s native collection methods inline in your test script:

```auto
`import groovy.json.JsonSlurper

def response = WS.sendRequest(findTestObject('your/api'))
def json = new JsonSlurper().parseText(response.getResponseBodyContent())

// Flat array
assert json.orders.status.contains('Invoiced')

```
