Write JSON from ProDataSets, temp-tables, and temp-table buffers
- Last Updated: June 13, 2019
- 4 minute read
- OpenEdge
- Version 13.0
- Documentation
The WRITE-JSON( ) method writes a JSON
string, Progress.Json.ObjectModel.JsonArray object, or
Progress.Json.ObjectModel.JsonObject object containing the
data from a corresponding temp-table, temp-table buffer, or ProDataSet object handle on which
you call the method. If you call the method on a temp-table buffer handle, it writes the
entire contents of the associated temp-table, not just the contents of the buffer. When
calling the method on a ProDataSet object handle, WRITE-JSON( ) writes the current version of data in each row of each table in the
ProDataSet object. The AVM ignores any before-image data for a ProDataSet unless you specify
an option to include it.
Note that you cannot call WRITE-JSON( ) on
a database buffer handle.
Note also that you cannot write a JsonArray from a ProDataSet object. If you call the method
on a ProDataSet object handle to write a JsonArray, WRITE-JSON( ) generates an error message and returns a value of
FALSE.
For JSON string output only, WRITE-JSON( ) provides the
option to format the JSON in a hierarchical manner using extra white space and line
breaks.
WRITE-JSON( ) does not write the data
object's schema to JSON, because JSON has no standardized support for schema. The lack of
schema information means that the JSON string does not explicitly include indexes and
data-relations.
The syntax for WRITE-JSON( ) is shown
below. The method returns TRUE or FALSE to
indicate whether the operation was successful.
Syntax
|
- target-type
- A
CHARACTERexpression that specifies the target type for the JSON output. Valid values are"FILE","STREAM","STREAM-HANDLE","MEMPTR","LONGCHAR","JsonArray", 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 pathname or a pathname relative to the current working directory. If a file with the specified name already exists, the AVM verifies that 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 WebSpeed-defined output stream (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 are finished using theMEMPTR, you must free the associated memory, by setting theMEMTERto zero bytes with theSET-SIZEstatement. - longchar
- A
LONGCHARvariable to contain the JSON string in memory. - JsonArray
- A reference to a
Progress.Json.ObjectModel.JsonArrayobject to which the AVM writes the contents of the associated temp-table. Any prior contents of the specified JsonArray are removed. - JsonObject
- A reference to a
Progress.Json.ObjectModel.JsonObjectobject to which the AVM writes the contents of the associated ProDataSet or temp-table. Any prior contents of the specified JsonObject are removed. - formatted
- An optional
LOGICALexpression whereTRUEdirects the AVM to format the JSON string in a hierarchical manner using extra white space, carriage returns, and line feeds. The default value isFALSE. If you specify the Unknown value (?), the method uses the default value ofFALSE. The formatted option is ignored for JsonArray and 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 that indicates whether the outer-most object is included in the JSON output.TRUEdirects the AVM to remove the outer-most object on output.FALSEdirects the AVM to include the outer-most object in the output. - write-before-image
- An optional
LOGICALexpression whereTRUEdirects the AVM to include ProDataSet before-image data and error information in the JSON output. The default value isFALSE.