Category: JS Objects
Resource links
Updated

This solution is summarized from an archived support forum post. This information may have changed. If you notice an error, please let us know in Discord.

How to Convert JSON Obj to XML and Vice Versa

Issue

As an AppSmith user, I need to be able to convert JSON to XML and XML to JSON within my application. To achieve this, the fast-xml-parser library has been integrated into the application and can be accessed through the xmlParser keyword. The library offers a jsonToXML function to convert JSON to XML and an xmlToJSON function to convert XML to JSON.

Resolution

fast-xml-parser 1 is integrated inside AppSmith and accessible through xmlParser keyword. Here is a JS Object:

export default {
	_J2Xparser: new xmlParser.j2xParser(),
	jsonToXML: (json = {"abc": "def"}) => {
		return this._J2Xparser.parse(json);
	},
	xmlToJSON: (xmlString = "<abc>def</abc>") => {
		return xmlParser.parse(xmlString);
	} 
}