Quickly transform XML to JSON with org.json.XML and ColdFusion

December 17, 2020 / Robert Zehnder

Work smarter, not harder


I was developing an API wrapper back in October that would allow posting a JSON to payload to a legacy SOAP endpoint. Transforming the JSON payload to a valid SOAP envelope was a bit of a painful experience but transforming an XML response back to ColdFusion was no problem at all.

function parse (required string xml) {
 return deserializeJSON(createObject("java", "org.json.XML").toJSONObject(xml)); 

In the end I wrote a custom parser and ended up losing this little snippet. Today I needed to convert XML to JSON again so I went digging for this, but this time I am documenting it since I am sure I will need it again.

Also note, you must have the org.json package available in your ColdFusion class path unless you are using javaloader.

About Robert Zehnder
Robert is a Senior Lead ColdFusion Engineer. In his spare time he enjoys hanging out with his family, his dog, and working on cool stuff.