PreviousNextIndex

WRITE-JSON( ) method

Writes a JSON string from a ProDataSet, a temp-table, or a temp-table buffer object. In the case of the temp-table buffer object, all the records of the temp-table associated with the buffer object are written to the JSON string—not just the one in the buffer.

Return type: LOGICAL

Applies to: Buffer object handle, ProDataSet object handle, Temp-table object handle

Syntax
WRITE-JSON ( mode, { file | stream | stream-handle | memptr | longchar } 
  [, formatted [, encoding [, omit-initial-values ] ] ] ) 

mode
file
stream
stream-handle
memptr
longchar
formatted
encoding
omit-initial-values

When writing data from a ProDataSet object that contains data-relations, you can nest child rows of a ProDataSet buffer within their parent rows in the resulting JSON string by:

You cannot write a JSON string from a database buffer.

The following code example defines a static ProDataSet object, attaches its data sources, fills the ProDataSet object, and writes the ProDataSet object to a JSON string in a nested manner:

DEFINE VARIABLE cTargetType AS CHARACTER NO-UNDO. 
DEFINE VARIABLE cFile       AS CHARACTER NO-UNDO. 
DEFINE VARIABLE lFormatted  AS LOGICAL   NO-UNDO. 
DEFINE VARIABLE lRetOK      AS LOGICAL   NO-UNDO. 
DEFINE TEMP-TABLE ttCustomer NO-UNDO LIKE Customer. 
DEFINE TEMP-TABLE ttOrder    NO-UNDO LIKE Order. 
DEFINE TEMP-TABLE ttInvoice  NO-UNDO LIKE Invoice. 
DEFINE DATASET dsOrderLog FOR ttCustomer, ttOrder, ttInvoice 
  DATA-RELATION CustOrd FOR ttCustomer, 
    ttOrder RELATION-FIELDS(CustNum,CustNum) NESTED 
  DATA-RELATION OrdInv FOR ttOrder, 
    ttInvoice RELATION-FIELDS(OrderNum,OrderNum) NESTED. 
DEFINE DATA-SOURCE dsCustomer FOR Customer. 
DEFINE DATA-SOURCE dsOrder    FOR Order. 
DEFINE DATA-SOURCE dsInvoice  FOR Invoice. 
BUFFER ttCustomer:HANDLE:ATTACH-DATA-SOURCE(DATA-SOURCE dsCustomer:HANDLE). 
BUFFER ttOrder:HANDLE:ATTACH-DATA-SOURCE(DATA-SOURCE dsOrder:HANDLE). 
BUFFER ttInvoice:HANDLE:ATTACH-DATA-SOURCE(DATA-SOURCE dsInvoice:HANDLE). 
DATA-SOURCE dsCustomer:FILL-WHERE-STRING = "WHERE Customer.CustNum = 2 ". 
DATASET dsOrderLog:FILL(). 
ASSIGN 
  cTargetType = "file" 
  cFile       = "dset.json" 
  lFormatted  = TRUE. 
lRetOK = DATASET dsOrderLog:WRITE-JSON(cTargetType, cFile, lFormatted). 

The following code example defines a static temp-table object, populates the temp-table object (code not shown), and writes the temp-table object to a JSON string:

DEFINE VARIABLE cTargetType AS CHARACTER NO-UNDO. 
DEFINE VARIABLE cFile       AS CHARACTER NO-UNDO. 
DEFINE VARIABLE lFormatted  AS LOGICAL   NO-UNDO. 
DEFINE VARIABLE lRetOK      AS LOGICAL   NO-UNDO. 
DEFINE TEMP-TABLE ttCust NO-UNDO LIKE Customer. 
/* Code to populate the temp-table */   
ASSIGN   
  cTargetType = "file"  
  cFile       = "ttCust.json"  
  lFormatted  = TRUE.  
lRetOK = TEMP-TABLE ttCust:WRITE-JSON(cTargetType, cFile, lFormatted). 

See also: ENCODING attribute, FIX-CODEPAGE statement, FOREIGN-KEY-HIDDEN attribute, NESTED attribute, READ-JSON( ) method


OpenEdge Release 10.2B
Copyright © 2009 Progress Software Corporation
PreviousNextIndex