util.JSON.stringify()

 

util.JSON.stringify() turns a record variable into a flat JSON string.

 

Syntax:

 

util.JSON.stringify(record_var)

 

Parameters:

 

record_var

a RECORD or DYNAMIC ARRAY program variable that must be turned into a JSON string

 

Usage and examples:

 

util.JSON.stringify() takes a RECORD or DYNAMIC ARRAY variable as a parameter, and turns it into a JSON string based on the general rules and specifications provided by json.org and implemented for Lycia.

 

example code

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 js

 

  CALL fgl_getkey()

END MAIN

 

obtained results

 

For greater details on how fgl data types are converted into JSON strings (and vice versa), refer here and here.

 

If the JSON string cannot be generated, the -8110 error - JSON serialization failed. See the description for more details - is returned to the user.

 

 

Example programs:

CVS server: client.querix.com

CVS repository: /lycia_doc_examples

User: client

Project: auxiliary_features/json

Program: util_JSON_stringify

 

Related articles:

util.JSON.format