web stats
Mirth Community - View Single Post - File listener
Thread: File listener
View Single Post
  #6  
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
Default

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:
    Code:
    var i, object = '', count = 0, escape = false, quote = false;
    while ((i = reader.read()) != -1) {
    	var ch = String.fromCharCode(i);
    	if (/\t|\r/.test(ch))
    		continue;
    	object += ch;
    	if (/\s/.test(ch))
    		continue;
    	if (ch == '\\' && !escape) {
    		escape = true;
    		continue;
    	}
    	if (ch == '"' && !escape)
    		quote = !quote;
    	if (ch == ',' && !quote)
    		object += '\t';
    	if (ch == '{')
    		count++;
    	if (ch == '}' && --count == 0)
    		return object.trim()+'\r';
    	escape = false;
    }
    return '';

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

Code:
{"key1":"value1","key2":"value2","key3":"value3"}
{"key4":"value4","key5":"value5","key6":"value6"}
And have Mirth Connect split it into two discrete messages, serialized as:

Code:
<delimited>
    <row>
        <column1>{"key1":"value1",</column1>
        <column2>key2:"value2",</column2>
        <column3>key3:"value3"}</column3>
    </row>
</delimited>
and

Code:
<delimited>
    <row>
        <column1>{"key4":"value4",</column1>
        <column2>key5:"value5",</column2>
        <column3>key6:"value6"}</column3>
    </row>
</delimited>
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