util.JSONObject.getLength() returns the number of the key:value pairs included in the JSON object.
Syntax
CALL util.JSONObject.getLength()
Usage and examples
util.JSONObject.getLength() is used to return or display how many key:value pairs there are in the JSON object.
MAIN
DEFINE json_obj util.JSONObject
LET json_obj
=util.JSONObject.parse('{"id":123, "name":"Scott"}')
DISPLAY json_obj.getLength()
CALL fgl_getkey()
END MAIN
MAIN
DEFINE json_obj util.JSONObject
DEFINE cust_rec RECORD
cust_num INTEGER,
cust_name VARCHAR(30),
order_id DYNAMIC ARRAY OF INTEGER
END RECORD
LET cust_rec.cust_num=345
LET cust_rec.cust_name="McMaclum"
LET cust_rec.order_id=4732
LET json_obj=util.JSONObject.fromFGL(cust_rec)
DISPLAY json_obj.getLength()
CALL fgl_getkey()
END MAIN
This method can be used together with util.JSONObject.getKey() and util.JSONObject.getType() in order to read the elements of JSON objects: