Skip to main content
%ToJSON()

Converts an instance of %DynamicAbstractObject. into a JSON string. If %ToJSON() doesn’t return an error, it will always return a string containing at least two characters ([] for an array or {} for an object). See “Converting Dynamic Entities to and from JSON” for details and examples.

   method %ToJSON(outstrm As %Stream.Object) as %String

parameters:

  • outstrm — optional. There are a number of possibilities:

    • If outstrm is not specified and the method is called via DO, the JSON string is written to the current output device.

    • If outstrm is not specified and the method is called as an expression, the JSON string becomes the value of the expression.

    • If outstrm is specified as an instance of %Stream.ObjectOpens in a new tab, the JSON string will be written to the stream (see “Serializing Large Dynamic Entities to Streams” for details and examples).

    • If outstrm is an object but is not an instance of %Stream.ObjectOpens in a new tab then an exception will be thrown.

    • If outstrm is not an object and is not null then it is presumed to be a fully qualified file specification (the full path to the file must be defined). The file is linked to a newly created %Stream.FileCharacterOpens in a new tab stream, the JSON string is written to the stream, and the stream is saved to the file on completion.

see also: %FromJSON(), %FromJSONFile()

class reference: %DynamicAbstractObject.%ToJSON()Opens in a new tab


FeedbackOpens in a new tab