Skip to content

Instantly share code, notes, and snippets.

@kousen
Last active January 11, 2020 21:47
Show Gist options
  • Save kousen/65cdae9cf0c7bc31d31f23be31ebda11 to your computer and use it in GitHub Desktop.
Save kousen/65cdae9cf0c7bc31d31f23be31ebda11 to your computer and use it in GitHub Desktop.
Astronauts in space at the moment
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