Discussion
· 12 hr ago

A small challenge for you - enhancing Interoperability message trace for mixed JSON and XML content

Hello community!
I have a small challenge for you :)

One of customers is sending quite a lot of messages between interoperability components, which mix standard request content and streams representing serialized JSON objects. As these JSON streams can be quite long (but not too long, just couple hundreds of characters) they would appreciate if the JSON content of stream was displayed in a nice-to-read way, using syntax highlighting by message trace view.

This picture illustrates the challenge - we are talking about the text framed by a red rectangle:
 I'd love to hear from anyone that you were able to come with some solution and post it to open exchange portal!

Dan

Discussion (1)2
Log in or sign up to continue

Hi,

Here is the sample code

 Set DCJson= {"name":"Janko","surname":"Hrasko","colors":["blue","green","yellow"]}
  
  Set formatter=##class(%JSON.Formatter).%New()
  Set sc=formatter.FormatToString(DCJson,.tJsonStr)
  Set newMsg = ##class(Ens.StreamContainer).%New()
  Set newMsg.Stream = ##class(%Stream.GlobalCharacter).%New()
  do newMsg.Stream.Write(tJsonStr)
  newMsg.Stream.Read()
 

Output:

{
  "name":"Janko",
  "surname":"Hrasko",
  "colors":[
    "blue",
    "green",
    "yellow"
  ]
}

Thanks,