The RTI_JSONX function allows you to evaluate a JSON (JavaScript Object Notation) expression. After passing in a JSON expression, you can evaluate the expression, and retrieve results. RTI_JSONX is a "wrapper" around the fully-featured RTI_RJSON, which uses the open source rapidJSON library.
Note: RTI_JSONX is only available in OpenInsight 10.x. It is the default stored procedure used when the RTI_JSON wrapper is called in OpenInsight 10.x.
return_value = RTI_JSONX(object, method [, param1 [, param2 [, param3]]])
The function has the following parameters:
Method | Description |
---|---|
Parse | Object: the JSON expression Return value: the handle to use for subsequent RTI_JSONX calls if successful, or 0 if unsuccessful. |
New | Object: unused, pass in empty string (“”) Param1: the type of variable to create. Valid types include “OBJECT” (for a generic object), “NUMBER”, “STRING”, “BOOLEAN”, “DATE”, and “ARRAY” Param2: the initial value of the created variable Param3: the delimiter to use when parsing an ARRAY, or the time part when parsing a DATE Return value: the evaluated variable object |
Stringify | Object: the variable that contains the previously-created JSON object Return value: the string representation of the JSON object |
GetValue | Object: the variable that contains the previously-created JSON object Param1: the "path" in the JSON string to the desired variable Param2: (optional) the name of the variable whose value should be retrieved. This can be an array element (enclosed in square braces, ie, “[1]”) if accessing an array object. Return value: the specified variable’s value |
SetValue | Object: the variable that contains the previously-created JSON object Param1: the name, or path (terminating in the name) of the variable whose value should be set. This can be an array element (enclosed in square braces, ie, “[1]”) if accessing an array object. Param2: the value to which the variable should be set Param3: The type of the value to set. Valid types include "NULL","BOOLEAN","NUMBER", and "STRING" Return value: none |
GetObject | Object: the variable that contains the previously-created JSON object Param1: the "path" in the JSON string to the desired variable Param2: (optional) the name of the variable whose value should be retrieved. This can be an array element (enclosed in square braces, ie, “[1]”) if accessing an array object. Return value: a JSON object representing the specified variable’s value |
SetObject | Object: the variable that contains the previously-created JSON object Param1: the name, or path (terminating in the name) of the variable whose value should be set. This can be an array element (enclosed in square braces, ie, “[1]”) if accessing an array object. Param2: the variable that contains the previously-created JSON object to which the variable should be set Return value: "1" if successful, "0" otherwise |
isObject | Object: the variable that contains the previously-created JSON object, or a handle to a previously-extracted element Param1: the name of the element inside Object to examine Param2: optional delimiter Return value: "1" if the element is an object, "0" otherwise |
GetProperties | Object: the variable that contains the previously-created JSON object Param1: the path (terminating in the name) of the variable whose properties should be returned Param2: the delimiter to use when returning the list of properties Return value: If Param1 specifies an array, then the return value is the number of elements, otherwise the return value is a list of the properties of the JSON object (separated by the specified delimiter in Param2) |
GetLength | Object: the variable that contains the previously-created JSON object Param1: the name of the variable to examine Return value: the number of elements in the named variable |
Delete | Object: the variable that contains the previously-created JSON object Param1: (optional) the path to the variable to delete from the object. If not specified, the entire object will be deleted Return value: "1" if successful, "0" otherwise |
Free Destroy | Object: the variable that contains the previously-created JSON object Return value: none |
Example 1:
myObject = RTI_JSON('', 'New', 'OBJECT') ; * generic object myNumber = RTI_JSON('', 'New', 'Number', '21') myString = RTI_JSON('', 'New', 'String', 'Hello World') myBool = RTI_JSON('', 'New', 'Boolean', '1') mydate = RTI_JSON('', 'New', 'Date', date(), time()) ; * javascript date object myArray = RTI_JSON('', 'New', 'ARRAY', '"A","B","C"') x = Rti_JSON(MyArray, 'SetValue', '[3]', 'D') v1 = Rti_JSON(MyArray, 'GetValue', '[0]') ;* v1 should now contain “A”
Example 2:
* given the following JSON string: * { "rti_table":"BOOKS", "id":"1021","BOOK_ID":"1021","TITLE":"China%20and%20the%20Manchus","AUTHOR":"Herbert%20A.%20Giles", "CHECK_OUT_DATE":"","RESERVED_BY":"","COMMENTS":"","CHECKED_OUT_BY":"","LAST_UPDATE_BY":"","LAST_UPDATE_DATE":"", "COVER_IMAGE":"","ISBN":"","BLERT":"","TM":"","COLUMN_13":"","COLUMN_14":"","COLUMN_15":"","COLUMN_16":"","COLUMN_17":"", "COLUMN_18":"","EMAIL_ADDRESS":"","PICTURE":"","DC":"E","ZZ1":"567","LISS":"","JW":"","COLUMN_25":"","COLUMN_26":"", "COLUMN_27":"","IS_AVAILABLE":"","COLUMN_29":"","DATETIMEWRITTEN":""} oRec = RTI_JSON( jString, 'Parse') table = RTI_JSON(oRec, 'GetValue', "rti_table") ;* should return BOOKS If table = '' Then Return '' End id = RTI_JSON(oRec, 'GetValue', "id") ;* should return 1021
Example 3:
myGrid = rti_json('','New', 'ARRAY') ;* create a new, empty array object list = Get_Property(@window:'.GRID', 'LIST') ;* get the elements of a list cnt = count(list, @fm) + ( list # '' ) k = 0 for i = 1 to cnt item = list<i,1> val = list<i,2> if item # '' then obj = rti_json('','New', 'STRING', val) ;* create a new string object for each value x = rti_json(myGrid, 'SetObject', '[':k:']', obj, 1) ;* store it into the array k+=1 end next myobj = rti_json('','New', 'OBJECT') ;* create a new empty object x = rti_json(myobj,'SetObject', 'myGrid', myGrid, 1) ;* put the previously-created grid into the object JString = rti_json(myobj, "Stringify") ;* return the JSON string