15.5.15

Pretty Printing with Gson in Groovy

#!/usr/bin/env groovy
@Grab('com.google.code.gson:gson:2.3.1')

import com.google.gson.*;

def gson = new GsonBuilder().setPrettyPrinting().create();
def jp = new JsonParser();

System.in.eachLine { line ->
    def je = jp.parse(line);
    println(gson.toJson(je));
}

No comments: