util.JSONArray.put

Sets an element by position in the JSON array object.

Syntax

util.JSONArray.put(
   index INTEGER,
   value value-type )
  1. index is the index of the element in the JSON array object.
  2. value is the value to be associated to the index.
  3. value-type can be a simple string or numeric type, a RECORD or an DYNAMIC ARRAY.

Usage

The put() method sets an element value by position in the JSON array object.

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

The index corresponding to the first element is 1.

If the element exists, the existing value is replaced.

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