util.JSONObject.put

Sets a name-value pair in the JSON object.

Syntax

util.JSONObject.put(
   name STRING,
   value value-type )
  1. name is a string defining the entry name.
  2. value is the value to be associated to the name.
  3. value-type can be a simple string or numeric type, a RECORD or an DYNAMIC ARRAY.

Usage

The put() method adds a name-value pair to the JSON object.

The first parameter is the name of the element. The second parameter can be a simple string or numeric value, or a complex variable defined as RECORD or DYNAMIC ARRAY.

If the element exists, the existing value is replaced.

IMPORT util
MAIN
    DEFINE obj util.JSONObject
    DEFINE rec RECORD
               id INTEGER,
               name STRING
           END RECORD
    DEFINE arr DYNAMIC ARRAY OF INTEGER
    LET obj = util.JSONObject.create()
    CALL obj.put("simple", 234)
    LET rec.id = 234
    LET rec.name = "Barton"
    CALL obj.put("record", rec)
    LET arr[1] = 234
    LET arr[2] = 2837
    CALL obj.put("array", arr)
    DISPLAY obj.toString()
END MAIN