util.JSON.parse

Parses a JSON string and fills program variables with the values.

Syntax

util.JSON.parse(
   source STRING,
   destination { RECORD | DYNAMIC ARRAY } )
  1. source is a string value that contains JSON formatted data.
  2. destination is the variable to be initialized with values of the JSON string.
    Important: The dest record is passed by reference to the method.

Usage

The util.JSON.parse() class method scans the JSON source string passed as parameter and fills the destination variable members by name.

The destination variable should have the same structure as the JSON source data, it can be a RECORD or a DYNAMIC ARRAY.

See JSON to Genero BDL conversion rules for details on how the destination variable is populated when the structures are not identical.

Example

IMPORT util
MAIN
    DEFINE cust_rec RECORD
               cust_num INTEGER,
               cust_name VARCHAR(30),
               order_ids DYNAMIC ARRAY OF INTEGER
           END RECORD
    DEFINE js STRING
    LET js='{ "cust_num":2735, "cust_name":"McCarlson",
              "order_ids":[234,3456,24656,34561] }'
    CALL util.JSON.parse( js, cust_rec )
    DISPLAY cust_rec.cust_name
    DISPLAY cust_rec.order_ids[4]
END MAIN