util.JSON.stringify

Transforms a record variable to a flat JSON formatted string.

Syntax

util.JSON.stringify(
   source RECORD )
  RETURNING result STRING
  1. source is the program record to be converted to a JSON string.
  2. result is a JSON formatted string created from the source record.

Usage

The util.JSON.stringify() class method takes a record variable as parameter, and generates the corresponding data string in JSON format, as defined in the [RFC4627] specification.

For more details about FGL to JSON conversion, see FGL to JSON conversion rules.

The method raises error -8110 if the JSON string cannot be generated.

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 cust_rec.cust_num = 345
    LET cust_rec.cust_name = "McMaclum"
    LET cust_rec.order_ids[1] = 4732
    LET cust_rec.order_ids[2] = 9834
    LET cust_rec.order_ids[3] = 2194
    LET js = util.JSON.stringify( cust_rec )
    DISPLAY util.JSON.format( js )
END MAIN
Displays following output:
{
    "cust_num": 345,
    "cust_name": "McMaclum",
    "order_ids": [4732,9834,2194
    ]
}