web stats
Mirth Community - View Single Post - File listener
Thread: File listener
View Single Post
Old 11-28-2012, 09:22 AM
narupley's Avatar
narupley narupley is online now
Mirth Employee
Join Date: Oct 2010
Posts: 7,126
narupley is on a distinguished road

It depends on how specifically you want you parse the JSON. You could use a Delimited Text batch script to separate JSON objects into discrete messages, and even make the serializer create a semi-useful XML structure for your transformer. For example, consider the following:

Delimited Text Properties
  • Column Delimiter: \t
  • Record Delimiter: \r
  • Quote Character: <empty>
  • Double Quote Escaping: <unchecked>
  • Escape character: <empty>
  • Ignore Carriage Returns: <unchecked>
  • Split Batch by Record: <unchecked>
  • Split Batch by Javascript:
    var i, object = '', count = 0, escape = false, quote = false;
    while ((i = reader.read()) != -1) {
    	var ch = String.fromCharCode(i);
    	if (/\t|\r/.test(ch))
    	object += ch;
    	if (/\s/.test(ch))
    	if (ch == '\\' && !escape) {
    		escape = true;
    	if (ch == '"' && !escape)
    		quote = !quote;
    	if (ch == ',' && !quote)
    		object += '\t';
    	if (ch == '{')
    	if (ch == '}' && --count == 0)
    		return object.trim()+'\r';
    	escape = false;
    return '';

The above code will basically allow you to take in a file containing:

And have Mirth Connect split it into two discrete messages, serialized as:


Also, note that due to a bug (which will be resolved in the next release), you'll have to copy the batch script over to the Delimited Text properties of the Source Outbound Protocol as well.
Attached Images
File Type: jpg Delimited Text Properties Screenshot.jpg (69.5 KB, 30 views)
Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

Nicholas Rupley
Work: 949-237-6069
Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.

- How do I foo?
- You just bar.
Reply With Quote