util.JSONArray.put() adds a new member to the specified JSON array.
util.JSONArray.insert() adds an element to the JSON array.
Syntax
CALL util.JSONArray.put(index INTEGER, value ANY_TYPE)
CALL util.JSONArray.insert(index INTEGER, value ANY_TYPE)
Parameters
util.JSONArray.put()
index INTEGER |
an index of the member of the specified JSON array |
value ANY_TYPE |
a value to be associated with this index |
util.JSONArray.insert()
index INTEGER |
an index of the element of the specified JSON array |
value ANY_TYPE |
a value to be associated with this index |
Usage and examples util.JSONArray.put()
Members added by util.JSONArray.put() must be assigned to a variable of the util.JSONArray data type.
The index of the first array member is 1.
The value of the array member can be a simple string or numeric value as well as a complex value of RECORD or DYNAMIC ARRAY data type.
MAIN
DEFINE json_arr util.JSONArray
LET json_arr=util.JSONArray.create()
CALL json_arr.put(1,123)
CALL json_arr.put(2,"abc")
DISPLAY json_arr.toString()
CALL fgl_getkey()
END MAIN
MAIN
DEFINE json_arr util.JSONArray
DEFINE cust_rec
RECORD
cust_id INTEGER,
cust_name STRING
END
RECORD
LET json_arr=util.JSONArray.create()
LET cust_rec.cust_id=15
LET cust_rec.cust_name="Barton, Timothy"
CALL json_arr.put(1,cust_rec)
DISPLAY json_arr.toString()
CALL fgl_getkey()
END MAIN
MAIN
DEFINE json_arr util.JSONArray
DEFINE da DYNAMIC ARRAY OF INTEGER
LET json_arr=util.JSONArray.create()
LET da[1] =1
LET da[2] =12
LET da[3] =123
CALL json_arr.put(1,da)
DISPLAY json_arr.toString()
CALL fgl_getkey()
END MAIN
If a JSON array has a member with the specified index already, the value of member will be changed:
Array members can be returned with the util.JSONArray.get() method.
Array members can be removed with the util.JSONArray.remove() method.
Usage and examples util.JSONArray.insert()
MAIN
DEFINE json_arr util.JSONArray
DEFINE da DYNAMIC ARRAY OF STRING
LET json_arr=util.JSONArray.create()
LET json_arr = util.JSONArray.parse('["aa","bb","cc"]')
DISPLAY json_arr.toString()
CALL json_arr.insert(1,"new_val")
DISPLAY json_arr.toString()
END MAIN