| The JSON class / util.JSON methods | |
Transforms a record variable to a flat JSON formatted string.
util.JSON.stringify( source RECORD ) RETURNING result STRING
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
{
"cust_num": 345,
"cust_name": "McMaclum",
"order_ids": [4732,9834,2194
]
}