HS.JSON.Utils

abstract class HS.JSON.Utils

Method Inventory

Methods

classmethod GlobalToJSON(pGlobalName="", pFormat As %String = "tw", pNodeName As %String = "^_", pLevel As %Integer = 0) as %Status
Write out the contents of the named global or % array pGlobalName in JSON format. Subscripts become JSON property names and $List values become JSON arrays.
pFormat is a flags string that controls output formatting options.
The following character option codes are supported:
1-9 : indent with this number of spaces (4 is the default with the 'i' format specifier)
b - line break before opening { of objects
i - indent with 4 spaces unless 't' or 1-9
n - newline (lf)
o - output empty objects
s - use strict JSON output - NOTE: special care should be taken when sending data to a browser, as using this flag may expose you to cross site scripting (XSS) vulnerabilities if the data is sent inside <script> tags. Zen uses this technique extensively, so this flag should NOT be specified for jsonProviders in Zen pages.
t - indent with tab character
u - output pre-converted to UTF-8 instead of in native internal format
w - Windows-style cr/lf newline
pNodeName is the name of a special JSON property used to hold the top-level value of a global node. It may also be a $List of the global node name and the array node name. Suggested array node name is "^#".
classmethod GlobalToJSONStream(pGlobalName As %String, ByRef pStream As %Stream.Object, pFormat As %String, pNodeName As %String) as %Status
Output the contents of a global or a % array to the given pStream stream object. If no stream object is given, a new %Stream.TmpBinary object will be returned by reference.
classmethod GlobalsToJSONStream(ByRef pArrOfGlobalNames As %String, pStream As %Stream.Object, pFormat As %String = "tw", pNodeName As %String) as %Status
Given an array of global or % array names in pArrOfGlobalNames, output the contents of each as JSON into the given pStream stream object, embedded within an outer wrapper JSON object, with each global's contents under a property name derived from the global's name
classmethod ParseJSONToGlobal(pJSON As %String, pGlobalName As %String, pNodeName As %String = "^_", Output pCharsProcessed As %Integer, pLevel As %Integer = 1, pFirstChar As %String = "") as %Status
Parse the input string pJSON containing JSON notation and store it in a named global or % array pGlobalName.
pJSON could also be a character stream.
JSON objects nested within JSON arrays cannot be imported because JSON arrays are imported as $List values. A $List value can contain other $List elements but not object references or COS arrays.
pNodeName is the name of a special JSON property used to hold the top-level value of a global node. It may also be a $List of the global node name and the array node name. Suggested array node name is "^#". pCharsProcessed and pLevel are used internally and do not have to be supplied. Note that this method assumes well-formed JSON content; it does not perform complete error checking.
classmethod ParseJSONToGlobals(pJSON As %String, ByRef pArrOfGlobalNames As %String, pNodeName As %String, Output pCharsProcessed As %Integer, pLevel As %Integer = 1, pFirstChar As %String = "") as %Status
Given JSON input parse the top level properties each into its own global or %array. If pArrOfGlobalNames contains a mapping from property names to global or array names, the JSON properties will be stored in the corresponding destinations. If this array argument is empty, the property names themselves will be used as the global or array names, and pArrOfGlobalNames will return containing a list of them. Otherwise properties found in the JSON with no matching name in this array will be stored to a destination named ^CacheTemp.JSONJunk
Feedback