Groovy web console

subscribe to the feed Subscribe
to this
site

Read network JSON

Published 5 months ago by Amol Chavan
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
import groovy.json.JsonSlurper

String JSON_URL = "https://api.carbonintensity.org.uk/intensity"
URL url = new URL(JSON_URL)
InputStream urlStream = null
urlStream = url.openStream()
BufferedReader reader = new BufferedReader(new InputStreamReader(urlStream))
JsonSlurper jsonSlurper = new JsonSlurper()
Object result = jsonSlurper.parse(reader)
println (result.toString())