web stats
Need help parsing XML using Javascript - Page 2 - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Thread Tools Display Modes
Old 10-22-2019, 12:12 PM
tjoyner1 tjoyner1 is offline
Mirth Newb
Join Date: Sep 2019
Posts: 10
tjoyner1 is on a distinguished road

Okay, about end of day here, I'll have more time tomorrow.

Thank you very much!
Reply With Quote
Old 10-23-2019, 04:46 AM
tjoyner1 tjoyner1 is offline
Mirth Newb
Join Date: Sep 2019
Posts: 10
tjoyner1 is on a distinguished road

<HttpResponse><Status>HTTP/1.1 200 OK</Status><Header><Field>
<Name>Date</Name><Value>Mon, 14 Oct 2019 18:18:49 GMT</Value></Field>
<Value>default-src https: 'unsafe-inline' 'unsafe-eval'</Value></Field>
Type</Name><Value>application/json; charset=utf-8</Value></Field>
<Body multipart="no">[{"nameF": "John", "nameL": "Doe", "location":
"University", "date": "10/11/2019"}, {"nameF": "Sara", "nameL": "Conner",
"location": "Pixie Land", "date": "10/12/2019"}</Body></HttpResponse

In my second destination i have a channel mapper

var GRB = msg['Body'].toString();
channelMap.put('GRB', GRB)

In my third destination a transformer *you helped me with

var GRB = JSON.parse(msg['Body'].toString());

I then get the error I posted earlier...

635: var GRB = msg['Body'].toString().split('{}');
636: for (var i = 0; i < GRB.length(); i++) {
637: GRB += (msg['Body'][i]['{}'].toString() + '\n')
638: channelMap.put('GRB', GRB)
DETAILS: SyntaxError: Empty JSON string

Thank you for your help!

Last edited by tjoyner1; 10-23-2019 at 04:48 AM.
Reply With Quote
Old 10-23-2019, 06:44 AM
jackwhaines jackwhaines is offline
Join Date: May 2011
Location: Kansas City, Missouri
Posts: 254
jackwhaines is on a distinguished road
Send a message via Skype™ to jackwhaines

It looks like you are still treating the data as a string and trying to parse it yourself. Let JSON.parse to the heavy lifting for you and deal with the JSON objects one by one. Also, add in some debugging with logger.info() in EACH step so you can "see" what Mirth "sees".

-= Jack Haines : Founder/CEO of Healthcare Integrations, LLC
-= jack.haines@HealthcareIntegrations.com
-= Mirth Connect (Advanced)-certified
-= Gold member of HL7.org
-= Available for Mirth Connect channel development and consultation! Schedule a FREE call with me at https://calendly.com/jackhaines
Reply With Quote

api, javascript, mirth connect, xml

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT -8. The time now is 10:59 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2020, vBulletin Solutions, Inc.
Mirth Corporation