fork download
  1. import static groovy.json.JsonOutput.toJson
  2. import static groovy.json.JsonOutput.prettyPrint
  3. def data = [data1: "data1", data2: "data2"]
  4. def jsonString = prettyPrint(toJson(data: data).toString())
  5. println jsonString
Success #stdin #stdout 0.9s 2252800KB
stdin
Standard input is empty
stdout
{
    "data": {
        "data1": "data1",
        "data2": "data2"
    }
}