Groovy web console

subscribe to the feed Subscribe
to this
site

Find and collect

Published 1 month ago by mrhaki
Actions Execute script  ▶ Edit in console Back to console Show/hide line numbers View recent scripts
import groovy.json.*
def jsonText = '{"values": [{"name": "Willem"}, {"name": "mrhaki"}]'
def json = new JsonSlurper().parseText(jsonText)

def allWillems = json.values.findAll { value -> "Willem" == value.name }.collect { value-> value.name }

println allWillems

def singleW = json.values.find { value -> value.name.startsWith("W") }.name

println singleW