Groovy web console

subscribe to the feed Subscribe
to this
site
Read values from json of same keys (via #groovywebconsole)
tweet this snippet Tweet
this
script

Read values from json of same keys

Published 6 months ago by Nitin Dhomse with tags Groovy JSON
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
import groovy.json.*
def json = '''{"book": [
                         {"id": "01","language": "Java","edition": "third","author": "Herbert Schildt"},
                         {"id": "07","language": "C++","edition": "second","author": "E.Balagurusamy"}
                       ]
              }'''
def jsonObj = new JsonSlurper().parseText(json)
println jsonObj.book.id