HS.JSON.Writer
class HS.JSON.Writer
Utility class for writing JSONMethod Inventory
- %CaptureWriteJSON()
- %CaptureWriteJSONToStream()
- %JSON()
- %JSONKey()
- %JSONStr()
- %Tab()
- %WriteJSON()
- %WriteJSONArray()
- %WriteJSONList()
- %WriteJSONObject()
- %WriteJSONProxy()
- %WriteJSONScalar()
- %WriteJSONStream()
- emitJSONProxyBody()
Methods
classmethod %CaptureWriteJSON(pValue, ByRef pOutput, pStringBuffer As HS.JSON.StringBuffer = $$$NULLOREF) as %Status
Write a value to a string/stream as JSON. This method simply wraps ..%WriteJSON() with redirection to an XDEV device
capture the output to a stream. The caller may specify the stream to avoid any additional copying, otherwise,
one will be created.
classmethod %CaptureWriteJSONToStream(pValue, ByRef pStream As %Stream.Object, pRewindStream As %Boolean = 0) as %Status
Write a value to a stream as JSON. This method simply wraps ..%WriteJSON() with I/O redirection in order to
capture the output to a stream. The caller may specify the stream to avoid any additional copying, otherwise,
one will be created.
Helper to convert any string value into a JSON-safe string value
Generate a properly escaped and quoted JSON object key
Generate a properly escaped and quoted JSON string
Generate a suitable indent (use spaces, not tabs)
The '%WriteJSON' method writes any value to JSON, regardless of it's type (scalar or object type).
It will handle the following types of value:
0) Scalar values
1) HS.JSON.Adapter: Calls %ToJSON() to export it (if pUseHSJSON is true)
2) HS.JSON.AdapterFHIR: Calls %ToFHIRJSON() to export it
3) %ZEN.proxyObject: Calls %ToJSON() to export it
4) %Document.Object: Calls ToJSON() to export it
5) %ListOfXXX: Writes a JSON list with each element; recursively calls %WriteJSON() on values
6) %ArrayOfXXX: Writes a JSON hash with each key/element; recursively calling %WriteJSON() to export values
7) Dynamic Object/Array (%Object/%Array or %DynamicObject/%DynamicArray): Calls $toJSON/%ToJSON to export it
8) Any other object: Uses the class dictionary metadata to emit the object; recursively calls %WriteJSON() to export values
classmethod %WriteJSONArray(pArray As %Collection.AbstractArray, pLevel As %Integer = 0, pTypeHint As %String = "") as %Status
Emit a JSON array (hash)
classmethod %WriteJSONList(pList As %Collection.AbstractList, pLevel As %Integer = 0, pTypeHint As %String = "") as %Status
Emit a JSON list
classmethod %WriteJSONObject(pObject As %RegisteredObject, pLevel As %Integer = 0) as %Status
Emit a JSON object (i.e. a non-%ToJSON() object). This is accomplished by walking the class's metadata and using
that to generate the JSON. Note that the client type of any datatype property is used to determine how to emit
the value (e.g. BOOLEAN is true/false ... see ..%WriteJSONScalar).
classmethod %WriteJSONProxy(pProxy As %ZEN.proxyObject, pLevel As %Integer = 0) as %Status
Emit a %ZEN.proxyObject
Emit a JSON scalar value
classmethod %WriteJSONStream(pStream As %Stream.Object, pLevel As %Integer = 0) as %Status
Emit a stream as JSON. Note: binary streams will be base64 encoded; character streams will be escaped appropriately
classmethod emitJSONProxyBody(pProxy As %ZEN.proxyObject, pLevel As %Integer = 0, ByRef pCount As %Integer) as %Status
Emit a %ZEN.proxyObject object body