PreviousNextIndex

READ-JSON( ) method

Reads a JSON string into a ProDataSet, a temp-table, or a temp-table buffer object.

Return type: LOGICAL

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

Syntax
READ-JSON ( source-type, { file | memptr | handle | longchar } 
  [, read-mode] ) 

source-type
file
memptr
handle
longchar
read-mode

For a dynamic ProDataSet or temp-table that is in the CLEAR state, the AVM infers the object’s schema from the data in the JSON value. If a dynamic temp-table is not in the PREPARED or CLEAR state, the method generates an error and returns FALSE. For more information about inferring schema from a JSON string, see OpenEdge Development: Working with JSON.

For a static ProDataSet or temp-table, the serialize name or object name must match the name found in the JSON string. If the names do not match, the AVM generates an error message and the method returns FALSE. The AVM ignores any columns in the JSON string that do not map to temp-table columns. If you use the SERIALIZE-NAME option in the DEFINE DATASET or DEFINE TEMP-TABLE statement, the AVM uses that name for matching, rather than the ABL object name.

You cannot read a JSON string into a database buffer.

The following code example creates a dynamic ProDataSet object from an empty ProDataSet handle, creates the objects schema by inference from the specified JSON string, and populates the temp-tables with records from the specified JSON document:

DEFINE VARIABLE cSourceType AS CHARACTER NO-UNDO. 
DEFINE VARIABLE cReadMode   AS CHARACTER NO-UNDO. 
DEFINE VARIABLE cFile       AS CHARACTER NO-UNDO. 
DEFINE VARIABLE lRetOK      AS LOGICAL   NO-UNDO. 
DEFINE VARIABLE hDSet       AS HANDLE    NO-UNDO. 
CREATE DATASET hDSet. 
ASSIGN 
  cSourceType = "file" 
  cFile       = "dset.json"  
  cReadMode   = "empty" 
lRetOK = hDSet:READ-JSON(cSourceType, cFile, cReadMode). 

The following code example creates a dynamic temp-table object from an empty temp-table handle, creates the object's schema by inference from the specified JSON string, and populates the temp-table with records from the same string:

DEFINE VARIABLE cSourceType AS CHARACTER NO-UNDO. 
DEFINE VARIABLE cReadMode   AS CHARACTER NO-UNDO. 
DEFINE VARIABLE cFile       AS CHARACTER NO-UNDO. 
DEFINE VARIABLE lRetOK      AS LOGICAL   NO-UNDO. 
DEFINE VARIABLE httCust     AS HANDLE    NO-UNDO. 
CREATE TEMP-TABLE httCust. 
ASSIGN 
  cSourceType = "file" 
  cFile       = "ttcust.json"  
  cReadMode   = "empty" 
lRetOK = httCust:READ-JSON(cSourceType, cFile, cReadMode). 

See also: IS-JSON attribute, WEB-CONTEXT system handle, WRITE-JSON( ) method


OpenEdge Release 10.2B
Copyright © 2009 Progress Software Corporation
PreviousNextIndex