jsValueGet

Returns the value associated with a key in a JSON container.

Syntax:

jsValueGet ( container-handle , key-name, [, key-delimiter] )

Parameters:

(s) container-handle: extender JSON container handle.

(s) key-name: name of an existing key including the full JSON path to the key.

(s) key-delimiter: [optional] single character used between key names in any path included in the key-name parameter (defaults to a dot character(".")).

Returns:

(s) value associated with a key-name.

 

This function retrieves the value of a key/value pair contained within the passed in JSON object, one of its child objects, in a JSON array or a JSON array element contained within the container or sub container. If the key's value is a JSON object (@JsonObj), the returned value will be a JSON extender object handle. If the returned key's value is a JSON array (@JsonArr), and a bracketed array index is not a postfix to the key name, the return value is a container-handle representing the array.

 

Container-Handle

The unique identifier returned from a call to the jsParse, jsConNew, jsValueGet functions, or by accessing WIL map element returned by the jsConMap function. The key-name with path must be a path to a key in  this container or one of  its child containers. 

  

Key-Name

The key name of a simple key/value pair, an array key name with bracketed index, or an empty bracket with bracketed index for an anonymous array. The name must include JSON path information when the pair exists in a child container and a bracketed index number when targeting an element of an array. See the About JSON Paths topic for detailed description of JSON paths.

 

Important:

 

Key-Delimiter

An optional parameter that must be a single character used between key name specifications in the JSON path. The default value is a dot ("."). The space(' '), backslash('\'), single-quote("'"), double-quote('"'), dollar-sign("$"), left-bracket("["), right-bracket("]") and grave-accent("`") cannot be used as delimiters.   

  

Example:
  AddExtender('ilcjs44i.dll', 0, 'ilcjs64i.dll')
  
  ; JSON data as a multi-line string constant.
  JsonData = $"{
    "pi":: 3.141,
    "happy":: true,
    "name":: "WIL JSON Extender",
    "nothing":: null,
    "answer":: {
      "everything":: 42
    },
    "list":: [1, 0, 2],
    "object":: {
      "currency":: "USD",
       "value":: 42.99,
    }
  }$"
  ; Create an JSON object.
  Object = jsParse(JsonData )
  ; Key to get a value for.
  Key = 'everything'
  ; Let the exender build the path.
  Path = jsKeyPaths(Object, 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.')
  ; Get the key's value.
  Value = jsValueGet(Object, Path[0])
  
  ; Do something with the value.
  Message('Value for "':Key:'"', "Key's value: ":Value)
  jsConClose()
  
See Also:

jsParse,  jsConNewjsValueTypejsKeyPaths