Groovy web console

subscribe to the feed Subscribe
to this

Convert dynamic XML rows to JSON key value pairs

Published 4 weeks ago by Anonymous
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
def xml = "<timeUDFLinks><u1t>UDF1</u1t><w3t>UDF3</w3t><u7t>UDF7</u7t></timeUDFLinks>"
def parsed = new XmlSlurper().parseText(xml)
def map = [(parsed[0].name): parsed.'*'.collectEntries{row -> [, row.text()]}]
println new groovy.json.JsonBuilder(map).toPrettyString()