import groovy.json.* if (args.size() == 0) { println("missing argument") System.exit(1) } def f = new File(args[0]) if (!f.exists()) { println("file doesn't exist") System.exit(1) } def lines = f.readLines() def keys = lines[0].split(',') def rows = lines[1..-1].collect { line -> def i = 0, vals = line.split(',') keys.inject([:]) { map, key -> map << ["$key": vals[i++]] } } println(JsonOutput.toJson(rows))