SaveJson Method (XDATA)


9.8A

 

The SaveJson method stores the XDATA nodes as a JSON formatted string into a file. The method uses the following format:

 

[label]

{object}.SaveJson

[GIVING {return}] using *FileName={filename}[,*Options={mask}]

Where:

label
Optional. A Program Execution Label.
object
Required. An XDATA object.
return
Optional. A Numeric Variable that receives a value to signify a pass or fail condition for the method execution.
filename
Required. A Character String Variable or literal that that specifies the path and file name used to write the JSON data stream.
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 ZERO flag is set if the {return} value is zero.

  2. The OVER flag is set TRUE if the {return} variable is too small where the returned value is truncated.

  3. The EOS flag is always cleared.

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

  5.  

    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.

     

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

  7.  

    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

     

  8. The {return} value is a zero if the method execution is successful. Otherwise, a non-zero value is returned to indicate an error has occurred. See the XDATA Method Return Values for more details.

  9. This method can return these values:

  10.  

    Value

    Meaning

    0

    XDATA_ERR_NONE (Success)

    16

    XDATA_ERR_FILE_CREATE

    17

    XDATA_ERR_FILE_TOO_BIG

    18

    XDATA_ERR_BAD_WRITE

 

 

See Also: XDATA, XDATA Methods, Method Syntax



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