Forum Discussion

henil_shah's avatar
henil_shah
Contributor
5 years ago
Solved

Create json in Groovy

Need to create Json like this "data": { "data1":"data1", "data2":"data2" } }   I'm able to create the below one but not the above one. I'm using def json = new JsonOutput().toJson(obj...
  • nmrao's avatar
    nmrao
    5 years ago

    henil_shah 

     

    Would you please check this script 

    You may test it online in the above link.

    import static groovy.json.JsonOutput.toJson
    import static groovy.json.JsonOutput.prettyPrint
    def data = [data1: "data1", data2: "data2"]
    def jsonString = prettyPrint(toJson(data: data).toString())
    log.info jsonString