Written by

Question Nezla · May 9, 2022

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

Comments

David Hockenbroch · May 9, 2022

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?

0
Pravin Barton · May 12, 2022

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.

0