How to automate or convert JSON into Katalon XML(variables script mode)

Hi,
I want to automata the process of converting the JSON to XML which will be used in Test case variables ( script mode)

If you are willing to write some lines in Katalon Studio Test Case, it can convert a JSON into XML. See, for example,

However, as you see, the solution is NOT automatic at all. I do not think there is a “generic tool” to convert a JSON to a XML. You need to help yourself.

hello,

I tried, works well

import groovy.json.JsonSlurper
import groovy.xml.MarkupBuilder

def json = '''
{
    "name": "sampleConfiguration",
    "description": "SampleDesc",
    "version": "1.0",
    "parameters": [
    {
        "name": "sampleParameter",
        "description": "parameter description",
        "value": "20",
        "enabled": "1"
    },
    {
        "name": "items",
        "description": "parameter with subparameters",
        "value":[
            {
                "name": "item",
                "description": "nested parameter",
                "value": "13"
            },
            {
                "name": "item",
                "description": "nested parameter 2",
                "value": "TEST"
            }
        ]
    }
]}'''



def xml = new JsonSlurper().parseText(json).with { j ->
	new StringWriter().with { sw ->
		new MarkupBuilder(sw)."$name"(version: version, description:description) {
			params {
				parameters.each { p ->
					if(p.value instanceof List) {
						"$p.name"(description:p.description) {
							p.value.each { v ->
								"$v.name"(description: v.description, v.value)
							}
						}
					}
					else {
						"$p.name"(description:p.description, p.value)
					}
				}
			}
		}
		sw.toString()
	}
}

println xml

<sampleConfiguration version='1.0' description='SampleDesc'>
  <params>
    <sampleParameter description='parameter description'>20</sampleParameter>
    <items description='parameter with subparameters'>
      <item description='nested parameter'>13</item>
      <item description='nested parameter 2'>TEST</item>
    </items>
  </params>
</sampleConfiguration>
2 Likes

Thank you.