Groovy web console

subscribe to the feed Subscribe
to this
site
JSON Parse (via #groovywebconsole)
tweet this snippet Tweet
this
script

JSON Parse

Published 4 months ago by Manuel Quindimil with tags json parse
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
import groovy.json.JsonSlurper   


def jsonSlurper = new JsonSlurper()       
def object = jsonSlurper.parseText('''{  "_class": "hudson.plugins.sloccount.model.SloccountReportStatistics",
  "languages": [
    {
      "comments": 2,
      "files": 4,
      "lines": 588,
      "name": "CSS"
    },
    {
      "comments": 4,
      "files": 6,
      "lines": 331,
      "name": "Bourne Shell"
    },
    {
      "comments": 0,
      "files": 698,
      "lines": 31293,
      "name": "JSON"
    },
    {
      "comments": 2584,
      "files": 721,
      "lines": 60462,
      "name": "Objective C"
    },
    {
      "comments": 4,
      "files": 4,
      "lines": 1621,
      "name": "HTML"
    },
    {
      "comments": 17,
      "files": 1,
      "lines": 50,
      "name": "YAML"
    },
    {
      "comments": 2572,
      "files": 796,
      "lines": 13810,
      "name": "C/C++ Header"
    },
    {
      "comments": 0,
      "files": 16,
      "lines": 24156,
      "name": "XML"
    },
    {
      "comments": 0,
      "files": 2,
      "lines": 29,
      "name": "JavaScript"
    },
    {
      "comments": 11269,
      "files": 1324,
      "lines": 57058,
      "name": "Swift"
    },
    {
      "comments": 0,
      "files": 5,
      "lines": 120,
      "name": "Markdown"
    },
    {
      "comments": 0,
      "files": 2,
      "lines": 60,
      "name": "Ruby"
    }
  ],
  "totalComments": 16452,
  "totalFiles": 3579,
  "totalLanguages": 12,
  "totalLines": 189578

}''')           
println object.languages.collect{it.name}
object.languages.find{it.name == 'Swift'}