Search code examples
arraysarraylistgroovykatalon-studiogroovy-console

Filtering/Selecting array values from index in Json in groovy


Trying to filter selective index. Fieldid values changes with every build, What do not change is fieldName": "TX.Sessionval.cost". Need to filter out the whole stringval and save into variable

fieldName": "TX.Sessionval.cost"
[
  {
   "Fieldid": "Fieldid/112",
    "fieldName": "TX.Sessionval.cost",
    "stringval": "jklah-dw-4c8d-8320-das313s3ASsda|000725N8WuUrfwAS7alP|banker_name"
  }
]

tried def slurper = new JsonSlurper() def result = slurper.parseText(response.getResponseBodyContent()) def newf = result.findAll { it.contains("TX.Sessionval.cost") } getting groovy.lang.MissingMethodException: No signature of method: java.util.LinkedHashMap$Entry.contains()

in Postman locator works fine

postman.setEnvironmentVariable("Stdid", jsonData.newFields[112].stringValue)

Solution

  • This works with me result.newFields.findAll { Map map -> map.get("fieldName").contains("TX.Sessionval.cost") }?.stringValue