Question
Rochdi Badis · May 9

Convert %CharacterStream to JSON and JSON to %Stream.GlobalCharacter

Hi Guys,

Can you pls let me how to convert %CharacterStream to JSON and also how to Convert JSON to %Stream.GlobalCharacter?

 

Thanks

Product version: Ensemble 2014.1
0
0 149
Discussion (3)3
Log in or sign up to continue

Are you just trying to get the json contained in a character stream into a string a vice versa? If so, just read and write to and from the stream:

set json = ""
while 'stream.AtEnd
{
    set json = json_stream.Read()
}

That should get you the contents of the stream into a string.

do stream.Write(json)

That should write the json to a stream.

Or is that not what you're trying to do?

If the character stream has JSON-format contents and you'd like to read it into a dynamic entity in ObjectScript, you can simply pass the stream into the %FromJSON method:

set obj = ##class(%DynamicAbstractObject).%FromJson(stream)

See the documentation for dynamic entity methods here.