Reputation: 1
I needed to convert the JSON data to XML.
Tried to use the JSON to XML Converter on JMeter but it did not convert the JSON. Instead, it is shown like this. Converted JSON to XML. Can you please help me regarding this.
Also, there is an error regarding this. Image
Upvotes: 0
Views: 756
Reputation: 163595
It's important to understand that there isn't one single definitive mapping from JSON to XML. Different converters will produce different results. Do you have a clear specification of the XML that you want to end up with? If you are happy with any old XML, then you can use any converter you like; alternatively, use any converter you like and then post-process the output to the form that you actually want using XSLT. If you're going to be using XSLT anyway, then it might be best to use the json-to-xml conversion that's built in to XSLT 3.0 so you're doing all the work in one place.
Upvotes: 0
Reputation: 168157
I would recommend going for Jackson Project which provides handy API suitable for JSON to XML conversion via ObjectMapper and XmlMapper classes so you should be able to perform JSON to XML conversion in any of JSR223 Test Elements using Groovy language as simple as:
def xml = new XmlMapper().writeValueAsString(new ObjectMapper().readValue('your JSON here', new TypeReference<Map<String, Object>>() { }))
Demo:
You will need the following libraries in JMeter Classpath in order to replicate the above exercise:
jackson-annotations-2.10.0.jar
jackson-core-2.10.0.jar
jackson-databind-2.10.0.jar
jackson-dataformat-xml-2.10.0.jar
jackson-module-jaxb-annotations-2.10.0.jar
jakarta.activation-api-1.2.1.jar
jakarta.xml.bind-api-2.3.2.jar
stax2-api-4.2.jar
woodstox-core-6.0.1.jar
Upvotes: 2