The following sample code (taken from the online help) shows how to read a JSON object into a temp-table, inferring the structure of the temp-table from the structure of the JSON.
Note that this method only works if the format of the JSON is similar to that which would be produced by the WRITE-JSON() method of the temp-table handle in a round-trip application. Specifically, READ-JSON() expects any nested child records to be represented as an Array.
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).
/* Sample Code to Read Data Loaded into the Temp-Table */
DEFINE VARIABLE hQuery AS HANDLE NO-UNDO.
DEFINE VARIABLE hBuffer AS HANDLE NO-UNDO.
DEFINE VARIABLE iNumFields AS INTEGER NO-UNDO.
DEFINE VARIABLE iLoop AS INTEGER NO-UNDO.
ASSIGN hBuffer = httCust:DEFAULT-BUFFER-HANDLE
iNumFields = hBuffer:NUM-FIELDS.
CREATE QUERY hQuery.
hQuery:SET-BUFFERS(httCust:DEFAULT-BUFFER-HANDLE).
hQuery:QUERY-PREPARE("FOR EACH " + httCust:NAME).
hQuery:QUERY-OPEN().
hQuery:GET-FIRST().
DO WHILE hQuery:QUERY-OFF-END = FALSE:
DO iLoop = 1 TO iNumFields:
// we use the STRING() function and BUFFER-VALUE attribute
// below instead of the STRING-VALUE attribute so that the
// data value isn't truncated to X(8) format. Thanks to the
// customer who noticed the truncation behavior.
MESSAGE STRING(hBuffer:BUFFER-FIELD(iLoop):BUFFER-VALUE,"X(80)" VIEW-AS ALERT-BOX.
END.
hQuery:GET-NEXT().
END.
hQuery:QUERY-CLOSE().
DELETE OBJECT hQuery.
DELETE OBJECT hBuffer.