StoreJson Method (XDATA)


9.8A

 

The StoreJson method stores the XDATA nodes as a JSON formatted string into a Character String variable. The method uses the following format:

 

[label]

{object}.StoreJson

[GIVING {return}] [using *Options={mask}]

Where:

label
Optional. A Program Execution Label.
object
Required. An XDATA object.
return
Optional. A Character String Variable that returns the result as a formatted JSON string.
mask
Optional. A Numeric Variable or decimal number that specifies a bit mask value to control the operations of this method.

Flags Affected: EOS, OVER, ZERO

Note the following:

  1. The EOS flag is set TRUE if the return variable is too small to receive the JSON string result without being truncated.

  2. The ZERO and OVER flags are always cleared.

  3. The *OPTIONS {mask} values are defined as follows:

  4.  

    Value

    Description

    0x2

    This bit value causes JSON constructs to be indented.

    0x4

    This bit value causes the JSON lines to output with a terminating <CR>+<LF> end of record sequence.

    0x40

    This bit value causes the TAB (0x09) character to be used when the indent mask bit (0x2) is being used. If this bit is turned off, a blank (0x20) character is used for the indent operations.

     

  5. The XDATA is converted to a JSON stream using the following rules:

  6.  

    Generate/bullet1.gif    JSON only uses the DOM_ATTRIBUTE_NODE, DOM_ELEMENT_NODE, and DOM_TEXT_NODE nodes from the XDATA. Any other DOM node types are ignored.

     

    Generate/bullet1.gif    A JSON array is a DOM_ELEMENT_NODE with a label of array and jsontype of JSON_TYPE_ARRAY. It can have multiple DOM_TEXT_NODE as values and multiple DOM_ELEMENT_NODE as object values.

     

    Generate/bullet1.gif    A JSON object is a DOM_ELEMENT_NODE with a label of object and jsontype of JSON_TYPE_OBJECT. It can have multiple DOM_ATTRIBUTE_NODE and DOM_ELEMENT_NODE nodes as key value pairs.

     

    Generate/bullet1.gif    See the following link for basic JSON syntax elements and rules:

     

    http://www.w3schools.com/js/js_json.asp

     

  7. The {return} value is a NULL Character String variable if there is a memory allocation error creating a working buffer to hold the JSON output.

 

 

See Also: XDATA, XDATA Methods, Method Syntax



PL/B Language Reference SaveXml Method (XDATA) StoreJsonSize Method (XDATA)