util.JSON.parse

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

Syntax

util.JSON.parse(
   source STRING,
   destination RECORD )
  1. source is a string value that contains JSON formatted data.
  2. dest is the RECORD variable to be set 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 RECORD members by name.

The destination variable should have the same structure as the JSON source data. See JSON to FGL conversion rules for details on how the destination variable is populated when the structures are not identical.

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