Groovy web console

subscribe to the feed Subscribe
to this
site
parse json and fetch a value based on relevant key value (via #groovywebconsole)
tweet this snippet Tweet
this
script

parse json and fetch a value based on relevant key value

Published 4 months ago by nmrao with tags parse json
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
def jsonString = """{
   "data":[
      {
         "Name":"ABCD",
         "Mobile":"9876543210"
      },
      {
         "Name":"EFGH",
         "Mobile":"8765432109"
      },
      {
         "Name":"IJKL",
         "Mobile":"7654321098"
      },
      {
         "Name":"MNOP",
         "Mobile":"6543210987"
      }
   ]
}"""
def json = new groovy.json.JsonSlurper().parseText(jsonString)
def result = json.data.find { it.Name == 'EFGH' }.Mobile
println result