prashanth ponugoti · Jan 6

How to convert DTL output to JSON

Hi Friends ,

We have requirement to convert source hl7 message to target json message using dtl.

Currently I have created persistent cls for json and completed the dtl.

DTL giving output as json equivalent xml.

Now how to convert DTL result xml object to json?

set oStream = ##class(%Stream.GlobalCharacter).%New()
set json = pResDTLresponseXml.%ToJSON()
set tSC = ##class("%ZEN.Auxiliary.altJSONProvider").%WriteJSONFromObject(pResDTLresponseXml,.json)
set tSC = oStream.Write(json)
if $$$ISERR(tSC) $$$LOGERROR("Error convert dynamic object to JSON stream: "_$System.Status.GetOneStatusText(tSC))
$$$TRACE("Transformed json: "_json)



Product version: Caché 2017.1
0 172
Discussion (1)2
Log in or sign up to continue

If your class is JSON-enabled (subclasses %JSON.Adaptor), it should be as simple as calling the message object's %JSONExportToStream() or %JSONExportToString() method:

Set tSC = msgObj.%JSONExportToStream(.oStream)