How to create existing JSON in groovy, using JsonBuilder? -


i'm looking definition (structure) of object can converted following json

 {     "header":{         "callbackurl":"",         "clientorderid":"a565132",         "clientoriginationid":"2345fe",         "serviceprovider":"verizon",         "transactionid":"eedt44567"     },     "customer": {         "nationalidtype":"",         "nationalid":"",         "addresses":[             {                 "type":"work",                 "postalcode":"330066"             }         ],         "serviceproviderauthentication":[             {                 "passcode":"",                 "securityquestion":"",                 "securityanswer":""             }         ]     },     "accountphonenumber":"",     "accountnumber":"" } 

if you're looking example of how jsonbuilder used create json you've given, here is

def json = new groovy.json.jsonbuilder()  json header: [         callbackurl:"",         clientorderid:"a565132",         clientoriginationid:"2345fe",         serviceprovider:"verizon",         transactionid:"eedt44567"     ],     customer:[         nationalidtype:"",         nationalid:"",         addresses: [             [                 type:"work",                 postalcode:"330066"             ]         ],         serviceproviderauthentication:[             [                 passcode:"",                 securityquestion:"",                 securityanswer:""             ]         ]     ],     accountphonenumber:"",     accountnumber:""  json.tostring() 

you might have been confused how create json doesn't have root. answer is: passing map.


Comments