Skip to content

Instantly share code, notes, and snippets.

@batmat
Created October 28, 2016 12:42
Show Gist options
  • Save batmat/b36e35c72b0105a6e5f6b6cccab76c70 to your computer and use it in GitHub Desktop.
Save batmat/b36e35c72b0105a6e5f6b6cccab76c70 to your computer and use it in GitHub Desktop.
Quick & Dirty JSON => CSV converter for http://stats.jenkins.io/plugin-installation-trend/jvms.json
import groovy.json.*
def slurper = new groovy.json.JsonSlurper()
def result = slurper.parse(new File('jvms.json'))
def vget(def map, def key) {
map.get(key) ?: "0"
}
final def JVM_VERSIONS = ["1.5", "1.6", "1.7", "1.8", "1.9"]
println 'timestamp,' + JVM_VERSIONS.join(',')
result['jvmStatsPerMonth'].each { month_map ->
println month_map.key + "," + ( JVM_VERSIONS.collect { vget(month_map.value, it) }.join(',') )
}
println "timestamp,1.7,1.8"
result['jvmStatsPerMonth_2_x'].each { month_map ->
println month_map.key + "," + ( ["1.7", "1.8"].collect { vget(month_map.value, it) }.join(',') )
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment