util.JSON.format()

 

util.JSON.format() formats and indents data as a JSON string.

 

Syntax:

 

util.JSON.format(data_string)

 

Parameters:

 

data_string

a string of JSON formatted data that must be organized in a certain way

 

Usage and examples:

 

util.JSON.format() makes JSON data string more readable by adding line breaks and indentation.

 

example code #1

(simple string)

MAIN

  DEFINE js STRING

    LET js = '{"cust_num":345,"cust_name":"McMaclum","order_ids":[4732,9834,2194]}'

    DISPLAY util.JSON.format(js)

  CALL fgl_getkey()

END MAIN

 

example code #2

(record)

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)

 

  CALL fgl_getkey()

END MAIN

 

obtained results