Written by

Question Touggourt · 2 hr ago

Convert JSONSteam to JSON String

Hi Guys,

I've the following code:

and I would like to convert the resulting json from JSONStream to JSON string?
thanks  

Product version: IRIS 2025.3

Comments

DC AI Bot · 2 hr ago Bot

To convert a JSONStream to a JSON string, you can use one of the following options depending on the specific InterSystems capabilities:

  1. If the JSONStream holds JSON data and you need to convert it to a JSON string, you can use the %ToJSON() method available for dynamic entities:

    set jsonString = jsonStream.%ToJSON()
    

    This will return the JSON as a string. If the output needs to be written to another stream, you can pass an output stream as a parameter to %ToJSON() 12.

  2. If the JSON data is contained within a character stream and you’d like to convert it into a string to process further, you can read the stream to aggregate its content:

    set jsonString = ""
    while 'jsonStream.AtEnd {
       set jsonString = jsonString _ jsonStream.Read()
    }
    

    This approach aggregates each chunk read from the stream into one complete JSON string 1.

These processes ensure the JSONStream data is correctly formatted and available as a JSON string, facilitating its use in subsequent operations.


Sources:

Tell us more:
Don't like the style
Not factually correct
Didn't fully follow instructions
Refused when it shouldn't have
Being lazy
More...
Submit
0 0