Write JSON from a temp-table buffer's current row
- Last Updated: June 13, 2019
- 4 minute read
- OpenEdge
- Version 13.0
- Documentation
The SERIALIZE-ROW( ) method serializes the
current row of the temp-table buffer handle on which you call it either as a JSON string or as
a Progress.Json.ObjectModel.JsonObject object.
Note that you cannot call SERIALIZE-ROW( )
on a database buffer handle.
For string outputs only, SERIALIZE-ROW( )
provides the option to format the output in a hierarchical manner using extra white space and
line breaks.
The syntax for SERIALIZE-ROW( ) is shown
below. The syntax is similar to that for the WRITE-JSON( )
method, with the addition of the target-format parameter. The method
returns TRUE or FALSE to
indicate whether the operation was successful or not.
Syntax
|
- target-format
- A
CHARACTERexpression that specifies the target format used to serialize the current row. Valid values are"JSON"and"XML". However, this method description focuses on serializing to JSON. - target-type
- A
CHARACTERexpression that specifies the target type for the JSON output. Valid values are"FILE","STREAM","STREAM-HANDLE","MEMPTR","LONGCHAR", and"JsonObject". - file
- A
CHARACTERexpression that specifies the name of a file to which the AVM writes the JSON string. You can specify an absolute path or a path relative to the current working directory. If a file with the specified name already exists, the AVM verifies if the file is writeable and overwrites the file. - stream
- A
CHARACTERexpression that specifies the name of a stream. If you specify the empty string (""), the AVM writes the JSON string to the default unnamed output stream. For WebSpeed, write the JSON string to the output stream defined by WebSpeed (WEBSTREAM). - stream-handle
- A
HANDLEvariable that specifies a stream object handle. - memptr
- A
MEMPTRvariable to contain the JSON string in memory. If you do not specify the encoding parameter, the AVM encodes the text written to theMEMPTRas "UTF-8". This method allocates the required amount of memory for the JSON string and sets the size of the variable. When you finish using theMEMPTR, you must free the associated memory by setting theMEMTERto 0 bytes with theSET-SIZEstatement. - longchar
- A
LONGCHARvariable which contains the JSON string in memory. - JsonObject
- A reference to a
Progress.Json.ObjectModel.JsonObjectobject to which the AVM writes the buffer's current row. Any prior contents of the specified JsonObject are removed. - formatted
- An optional
LOGICALexpression whereTRUEdirects the AVM to format a JSON string in a hierarchical manner using white space, carriage returns, and line feeds. The default value isFALSE. If you specify the Unknown value (?), the method uses the default valueFALSE. The formatted option is ignored for JsonObject targets. - encoding
- An optional
CHARACTERexpression that specifies the name of the character encoding the AVM uses to write the JSON output. The default encoding is "UTF-8". - omit-initial-values
- An optional
LOGICALexpression whereTRUEdirects the AVM to exclude temp-table fields containing their initial values from the JSON output, andFALSEdirects the AVM to include all temp-table field data in the output. The default value isFALSE. If you specify the Unknown value (?), the method uses the default value ofFALSE. - omit-outer-object
- An optional
LOGICALexpression indicating whether the outer-most object in JSON output is included.TRUEdirects the AVM to remove the outer-most object on output.FALSEdirects the AVM to include the outer-most object in the output.
The following example demonstrates the use of
SERIALIZE-ROW( ):
|
The SERIALIZE-ROW( ) method produces the
following JSON string outputs. The JSON output below is bcust.json with omit-outer-object set to
FALSE.
|
The JSON output below is bcust2.json with
omit-outer-object set to TRUE.
|