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

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #11  
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
Default

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

Thank you very much!
Reply With Quote
  #12  
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
Default

<HttpResponse><Status>HTTP/1.1 200 OK</Status><Header><Field>
<Name>Server</Name><Value>Microsoft-IIS/10.0</Value></Field><Field>
<Name>X-Content-Type-Options</Name><Value>nosniff</Value></Field><Field>
<Name>Connection</Name><Value>keep-alive</Value></Field><Field>
<Name>Pragma</Name><Value>no-cache</Value></Field><Field><Name>X-
Permitted-Cross-Domain-Policies</Name><Value>none</Value></Field><Field>
<Name>Date</Name><Value>Mon, 14 Oct 2019 18:18:49 GMT</Value></Field>
<Field><Name>Strict-Transport-Security</Name><Value>max-
age=31536000</Value></Field><Field><Name>Cache-Control</Name><Value>no-
cache</Value></Field><Field><Name>Content-Security-Policy</Name>
<Value>default-src https: 'unsafe-inline' 'unsafe-eval'</Value></Field>
<Field><Name>X-AspNet-Version</Name><Value>4.0.30319</Value></Field>
<Field><Name>Vary</Name><Value>Accept-Encoding</Value></Field><Field>
<Name>Expires</Name><Value>-1</Value></Field><Field><Name>Content-
Type</Name><Value>application/json; charset=utf-8</Value></Field>
</Header>
<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)
LINE NUMBER: 634
DETAILS: SyntaxError: Empty JSON string


Thank you for your help!

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

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
Reply

Tags
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 11:29 AM.


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