Converting JSON message to XML
JSON and XML are the de facto data interchange standard formats used by industry applications. The two formats share many similarities, but have different goals in their design. JSON is designed to be a data exchange language, which is human readable and easy for computers to parse and use. XML also shares the readability goal, but suffers from a higher degree of verbosity and complexity.
Nevertheless, the two formats are here to stay, and a case for converting from one format to the other is recurring in the IT industry.
This recipe shows how to convert a JSON document into XML using a Groovy only solution as well as introducing a less "groovier" solution in the There's more... section.
Getting ready
The JSON document to convert is the ui.json
file that we already encountered in the Parsing JSON messages with JsonSlurper recipe.
How to do it...
The conversion is based on groovy.xml.MarkupBuilder
, which allows full control on the final output but makes the code more...