web stats
JSON.Stringify() does not work in mith 3.3.0.7801 - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 10-12-2015, 08:50 AM
vibinChander vibinChander is offline
OBX.2 Kenobi
 
Join Date: Jul 2015
Location: Chennai
Posts: 74
vibinChander is on a distinguished road
Send a message via Skype™ to vibinChander
Default JSON.Stringify() does not work in mith 3.3.0.7801

Hi guys,
im trying to convert the incoming data to JSON data, Im trying to convert this data using JSON.Stringify() . But it specifies that it cannot stringify the object, I'm just pasting my sample code here.

Code:
var obj={};
obj.k={
"fathername":msg['PID']['PID.6']['PID.6.1'],
"mothername":msg['PID']['PID.6']['PID.6.2'],
}
var m= JSON.Stringify(obj);
logger.info(m);
can you guys help me out in this?
Reply With Quote
  #2  
Old 10-12-2015, 11:31 AM
mcalKno mcalKno is offline
 
Join Date: Apr 2015
Location: Pennsylvania
Posts: 247
mcalKno is on a distinguished road
Default

Checkout the new API for JsonUtil. I don't believe stringify is necessary any longer.

Quote:
Mirth Connect has always supported JSON, since you can call "JSON.parse" and "JSON.stringify" directly in JavaScript. However now in 3.3, we've added a new JSON data type to make working with it even easier!
JSON-specific syntax highlighting and message tree structure
The "msg" and "tmp" variables in filters/transformers will automatically be converted to/from JavaScript objects. No need to call parse or stringify!
A new JsonUtil utility class was added, so you can easily pretty print JSON data before sending it out.
Reply With Quote
  #3  
Old 10-12-2015, 03:02 PM
glen4medica glen4medica is offline
Mirth Newb
 
Join Date: Apr 2011
Location: Eugene, Oregon
Posts: 19
glen4medica is on a distinguished road
Default

You may need to do the following:
"fathername":msg['PID']['PID.6']['PID.6.1'].toString()
Reply With Quote
  #4  
Old 10-12-2015, 11:13 PM
vibinChander vibinChander is offline
OBX.2 Kenobi
 
Join Date: Jul 2015
Location: Chennai
Posts: 74
vibinChander is on a distinguished road
Send a message via Skype™ to vibinChander
Default Thanks Guys

Yeah, Thats a better improvement in mirth 3.3.0.7801, there is no need to include JSON.Stringify() function. Just including .toString() to th message and logging the object works for me. Thanks for the info guys.
Reply With Quote
  #5  
Old 10-13-2015, 06:47 AM
narupley's Avatar
narupley narupley is online now
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,119
narupley is on a distinguished road
Default

The reason why you needed to add toString() is because by default the E4X XML prototype does not implement toJSON, which is what stringify uses to convert an object to a JSON string. This was a problem even in earlier versions, not just 3.3. It will be addressed in 3.3.1: MIRTH-3796
__________________
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
Reply

Tags
hl7v3, json, mirth3.0, mirth3.3.0

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:20 AM.


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