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

Work smarter, not harder cfml

December 15, 2020 / Robert Zehnder

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.