web stats
Mirth Community - View Single Post - CSV into JSON !
Thread: CSV into JSON !
View Single Post
  #2  
Old 04-08-2019, 01:27 AM
schillert schillert is offline
OBX.1 Kenobi
 
Join Date: Jul 2012
Posts: 29
schillert is on a distinguished road
Default

Hi,

here is a rather pedestrian approach which works.
I'm just writing the JSON object into a string.
Code:
tmp = "";
var numCols=msg["row"].children().length();
for each (seg in msg["row"].children()) {
	var num = parseInt(seg.name().toString().replace(/column/,""),10);
	if (num==1) {
		tmp += '{"Day":"'+msg['row']['column1'].toString()+'",';
	} else if(num==2) {
		tmp+='"Fruits":[{"Fruit'+(num-1).toString()+'":"'+msg['row']['column'+num.toString()].toString()+'"';
	} else {
		tmp+=',"Fruit'+(num-1).toString()+'":"'+msg['row']['column'+num.toString()].toString()+'"';
	}
	if(num==numCols) {
		tmp += "}]}"
	}

}
msg=tmp;
Perhaps somebody can do it more elegantly....
Reply With Quote