Last active
January 11, 2020 21:47
-
-
Save kousen/65cdae9cf0c7bc31d31f23be31ebda11 to your computer and use it in GitHub Desktop.
Astronauts in space at the moment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import groovy.json.* | |
import groovy.transform.* | |
import com.google.gson.Gson | |
@Grab('com.google.code.gson:gson:2.8.6') | |
@Canonical | |
class Assignment { String name; String craft } | |
@Canonical | |
class Response { String message; int number; Assignment[] people } | |
String jsonTxt = 'http://api.open-notify.org/astros.json'.toURL().text | |
def json = new JsonSlurper().parseText(jsonTxt) | |
println "There are ${json.number} people in space" | |
new Gson().fromJson(jsonTxt, Response).people.each { | |
println it | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment