Skip to content

Instantly share code, notes, and snippets.

@robertz
Last active January 3, 2021 20:32
Show Gist options
  • Save robertz/f82feb5dd6ae1b3701f8f9c5c0d7b7a8 to your computer and use it in GitHub Desktop.
Save robertz/f82feb5dd6ae1b3701f8f9c5c0d7b7a8 to your computer and use it in GitHub Desktop.
Using org.json.XML to convert XML to JSON inside a ColdBox event handler. The org.json java library will need to be downloaded to the ColdBox /lib folder or added to the server.
component extends="coldbox.system.EventHandler" {
property name = "SpiderService" inject;
function xmlToJson (event, rc, prc) {
var u = event.getValue("u", "");
prc['data'] = {};
if(u.len()){
var obj = createObject("java", "org.json.XML");
cfhttp(url = rc.u, method = "get");
if(isXML(cfhttp.fileContent)) prc.data.append(deserializeJSON(obj.toJSONObject(cfhttp.fileContent, true)));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment