For those who are interested, here is what I wanted to do. There is a column in the database containing dynamic JSON objects. The object will contains pairs of keys and values. like {"city":"Red Deer, Count of ", "dueDate":"2010-10-10"}.
As you can see, this json object will fail if I pass it to the json2xml services as it is missing the root tag. The following is the script that wrote to convert the tag in json to xml and append it to the end of the DocOut.
--------------------------------------------------------------------------------
importPackage(com.ibi.edaqm);
importPackage(com.iwaysoftware.iwscript);
function execute(){
var transformResult = new XDDocument();
var transform = tools.getTransform("QueryResult_TF");
var status = transform.execute(ctx.getDocIn(), ctx.getDocOut());
var root = ctx.getDocOut().getRoot();
var json_elements = new XDNode("JSON_Elements");
var json_to_xml = ctx.getDocOut().getRoot().findByName("JSON_XML");
var json_string = json_to_xml.getValue().replace('",', '";');
var json_string_new = json_string.replace('"', '').replace('{','').replace('}','');
var json_Array = json_string_new.split(";");
var newNode = null;
//tools.info("json_Arry = " + json_Array);
//tools.info("json_Array length = " + json_Array.length);
for (var i = 0; i < json_Array.length; i++){
if ((i == 0) && (json_Array[i].length() == 0)){
//do nothing
}else{
//tools.info("json_Array object " + i);
//tools.info("json_Array object = " + json_Array[i]);
var tag_name = json_Array[i].substring(0,json_Array[i].indexOf(":"));
var tag_value = json_Array[i].substring(json_Array[i].indexOf(":") + 1, json_Array[i].length());
newNode = new XDNode(tag_name.trim());
newNode.setValue(tag_value);
json_elements.setLastChild(newNode);
}
}
root.setLastChild(json_elements);
//tools.info("Testing of QueryResult_TF");
//ctx.setDocOut(transformResult);
//tools.debug(ctx.getDocOut());
return status;
}
iWay 5.5, 6.01
Windows
all output (Excel, HTML, PDF)