guides:programming:programmers_reference_manual:rti_json9_function

RTI_JSON9 Function

The RTI_JSON9 function allows you to evaluate either a javascript function or a JSON (JavaScript Object Notation) expression. After passing in a javascript function or a JSON expression, you can invoke the function or evaluate the expression, and retrieve results.

Note: RTI_JSON9 uses a javascript implementation of the JSON parser. In OpenInsight 10 by default, RTI_JSON uses an open source library (rapidJSON).

RTI_JSON9(handle, action, param1, param2, param3)

The function has the following parameters:

ActionDescription
ParseHandle: the javascript function or JSON expression

Return value: the handle to use for subsequent RTI_JSON9 calls if successful, or 0 if unsuccessful
NewHandle: unused, pass in empty string (“”)

Param1: the type of variable to create. Valid types include “OBJECT” (for a generic object), “NUMBER”, “STRING”, “BOOLEAN”, “DATE”, “REGEXP”, and “ARRAY”

Param2: the initial value of the created variable

Param3: the optional time value for a DATE, or the optional flags for a REGEXP

Return value: the evaluated variable object
StringifyHandle: the variable that contains the previously-created javascript or JSON object

Return value: the string representation of the JSON object
GetValueHandle: the variable that contains the previously-created javascript or JSON object

Param1: 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
SetValueHandle: the variable that contains the previously-created javascript or JSON object

Param1: 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

Return value: 0 if successful, or OLE error code
GetObjectHandle: the variable that contains the previously-created javascript or JSON object

Param1: the name of the variable to extract

Return value: the handle of the extracted object to use for subsequent RTI_JSON9 calls
SetObjectHandle: the variable that contains the previously-created javascript or JSON object

Param1: the name of the element to update

Param2: the variable that contains the previously-created JSON object to insert

Return value: handle if successful, or null otherwise
isObjectHandle: the element to examine

Return value: '1' if the element is an object or '0' otherwise
GetPropertiesHandle: the variable that contains the previously-created javascript or JSON object

Return value: @VM delimited list of the properties of the javascript or JSON object
GetLengthHandle: the variable that contains the previously-created javascript or JSON object

Param1: the name of the element to evaluate

Return value: the length of the specified element
EvalHandle: unused, pass in empty string (“”)

Param1: javascript source or JSON string

Return value: the evaluated object
DeleteItem
DeleteObject
Handle: the variable that contains the previously-created javascript or JSON object

Param1: the name of the element to delete

Return value: '1' if successful, '0' otherwise
RefreshHandle: unused

Param1: unused

Return value: none

Example 1:

myObject = RTI_JSON9('', 'New', 'OBJECT')  ; * generic object

myNumber = RTI_JSON9('', 'New', 'Number', '21')

myString = RTI_JSON9('', 'New', 'String', 'Hello World')

myBool   = RTI_JSON9('', 'New', 'Boolean', '1')

mydate   = RTI_JSON9('', 'New', 'Date', date(), time())  ; * javascript date object

myRegEx  = RTI_JSON9('', 'New', 'REGEXP', "\bt[a-z]+\b") ; * regular expression

myArray  = RTI_JSON9('', 'New', 'ARRAY', '"A","B","C"')

x = Rti_JSON9(MyArray, 'SetValue', '[3]', 'D')

v1 = Rti_JSON9(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_JSON9( jString, 'Parse')

table = RTI_JSON9(oRec, 'GetValue', "rti_table")  ;* should return BOOKS

If table = '' Then

   Return ''

End

id  = RTI_JSON9(oRec, 'GetValue', "id") ;* should return 1021

Example 3:

myGrid = rti_json9('','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_json9('','New', 'STRING', val)   ;* create a new string object for each value

     x = rti_json9(myGrid, 'SetObject', '[':k:']', obj, 1) ;* store it into the array

     k+=1

  end   

next  

myobj = rti_json9('','New', 'OBJECT') ;* create a new empty object

x = rti_json9(myobj,'SetObject', 'myGrid', myGrid, 1) ;* put the previously-created grid into the object

JString = rti_json9(myobj, "Stringify") ;* return the JSON string
 
  • guides/programming/programmers_reference_manual/rti_json9_function.txt
  • Last modified: 2025/04/07 14:54
  • by bshumsky