jsConNew

Creates an empty JSON container.

Syntax:

jsConNew ( container-type )

Parameters:

(i) container-type: a JSON data type indicating the type of container to create. See below

Returns:

(a) container-handle: A JSON extender handle to an empty JSON object or empty JSON array.

 

jsConNew creates and returns a JSON extender container handle that can be used as the root container of a new JSON container tree or added to another container as the value part of a JSON key/value pair or an element value of another JSON array.

 

Container-Type

Use the parameter to control the type of container handle returned by the function. JSON object container handle values are accessed by their key names whereas JSON array container handles values are accessed by their element zero-based index.

 

  Possible Container-Type and Parameter Contents

 

Value Type

Meaning

@JsonArr (16)

Create an empty JSON array

@JsonObj (32)

Create an empty JSON object

 

  

Example 1:
  AddExtender('ilcjs44i.dll', 0, 'ilcjs64i.dll')
  
  ; Start a new JSON.
  Object = jsConNew(@JsonObj)  
  ; Add a string pair to the new object.
  jsValueAdd(Object, 'first key', 'helo world', @JsonStr)
  
  ; Add a sub-object with a key.
  Sub = jsConNew()
  jsValueAdd(Sub, 'second key', 'under world', @JsonStr)
  jsValueAdd(Object, 'sub-key', Sub, @JsonObj)
  
  ; Check if it worked.
  Path = jsKeyPaths(Object, 'second key')
  ; Check the assumption of one pair with the name.
  Terminate(1!=ArrInfo(Path, 1), 'Error', 'None or more than one pair with key name.')
  TestVal = jsValueGet(Object, Path[0])
  Message('Sub-key Value', 'The "second Key" value is "':TestVal:'"')
  
  jsConClose()
  
Example 2:
  AddExtender('ilcjs44i.dll', 0, 'ilcjs64i.dll')
  
  ; Create a new JSON anonymous array.
  Array = jsConNew(@JsonArr)
  
  ; Add a string pair to the new array.
  ; Note anonymous array path to array element.
  jsValueAdd(Array, '[][0]', 'helo world', @JsonStr)
  
  ; Add an object as an second array element.
  Object = jsConNew(@JsonObj)
  jsValueAdd(Object, 'element-key', 'array world', @JsonStr)
  jsValueAdd(Array, '[][1]', Object, @JsonObj)
  
  ; Check if it worked.
  Path = jsKeyPaths(Object, 'element-key')
  ; Check the assumption of one pair with the name.
  Terminate(1!=ArrInfo(Path, 1), 'Error', 'None or more than one pair with key name.')
  TestVal = jsValueGet(Object, Path[0])
  Message('Array Element Object  Value', 'The "element-key" value is "':TestVal:'"')
  
  jsConClose()
  
See Also:

jsParse, jsValueAdd, jsValueType, jsValueGet