Jirong Hu
Jirong Hu

Reputation: 2375

How to parse the json response returned from the HttpBuilder in Groovy?

The following is what GitHub returns from a REST GET method. How to parse it using JSON?

response.success = { resp, reader ->
            result = reader.text
        }

[{"login":"ghost","id":1,"avatar_url": ....},{"login":"github-enterprise","id":2,"avatar_url": ....}]

Upvotes: 0

Views: 1897

Answers (1)

Cortwave
Cortwave

Reputation: 4907

You can use awesome tool for working with json - json slurper:

    def slurper = new JsonSlurper()
    def result = slurper.parseText(result)
    def firstLogin = result[0].login
    def secondId = result[1].id

Upvotes: 1

Related Questions