aaronpliu
7 years agoFrequent Contributor
Convert a flat JSON object to x-www-form-urlencoded
As captioned:
def jsonData = ''' { "name":"John", "age":30, "city":"New York" } ''' def slurper = new groovy.json.JsonSlurper().parseText(jsonData) def str = new StringBuilder() def iter = slurper.keySet().iterator() while(iter.hasNext()){ def key = iter.next().toString() def value = slurper.get(key).toString().trim().replaceAll(" ","20%") str.append("$key=$value&") } log.info str[0..str.size()-2]