jsConMap

Creates a WIL map from the contents of a JSON object or JSON array.

Syntax:

jsConMap ( container-handle [, map-content] )

Parameters:

(s) container-handle: handle to the JSON object or array to convert.

(s) map-content: [optional] @JsonValue(1)or @JsonType(2) (defaults to @JsonValue).

Returns:

(a) map: WIL map with each JSON object key as a WIL map key or with each JSON array index as the map key. The map values are either the JSON the values or JSON types of each JSON object key or JSON array index.

 

This function converts either a JSON object or a JSON array into a WIL map. When the container-handle parameter pointers to a JSON object the output map uses the object's key names as WIL map keys. When the container handle pointers to a JSON array the WIL map keys are the zero-based indices of the array. The map values can either be the JSON values for each key or index or the JSON type of each key or index value depending on the map-content type indicated in the second parameter.

 

Container-Handle

The unique identifier returned from a call to the jsParse, jsConNew, jsValueGet functions, or by accessing WIL map element returned by a separate call to the  jsConMap function.

  

Map-Content

An optional parameter that determines the returns map's values.

 

The parameter can have one of the following values:

  

Parameter Value

Meaning

@JsonValue (1)

Make each map key value is a JSON key's or index's value. This is the default when the parameter is not provided. Note that nested JSON objects and JSON arrays have a extender container-key as a value. (The default.)

@JsonType (1)

Make each map key value is a  JSON object key's or array index's JSON data type. Possible JSON data types are listed in the table below.

  

When @JsonType is used in the Map-Content parameter the returned map's keys will have one of the following extender defined constants as a value:

  

Map Key Value

Meaning

@JsonNull (1)

An empty value represented by the text string "null".

@JsonBool (2)

An true or false value represented but the text string "true" or "false".

@JsonNum (4)

A 32-bit integer, 64-bit integer, or floating point number.

@JsonStr (8)

A text string.

@JsonArr (16)

A JSON array that is represented by an extender JSON container handle when the value is requested using @JsonValue (1) .

@JsonObj (32)

A JSON object this represented by an extender JSON container handle when the value is requested using @JsonValue (1) .

  

Example:
  AddExtender('ilcjs44i.dll', 0, 'ilcjs64i.dll')
  
  ; JSON object text.
  strJson = $"{
    "pi":: 3.141,
    "happy":: true,
    "name":: "WIL JSON Extender",
    "nothing":: null,
    "answer":: {
      "everything":: 42
    },
    "list":: [1, 0, 2],
    "object":: {
      "currency":: "USD",
       "value":: 42.99,
  
       "nested object":: {
         "value":: "bird egg"
       }
    },
    "value":: "Top level value"
  }$"
  ; Get a JSON object.
  Object = jsParse(strJson)
  ; Find the first sub-object.
  TypesMap = jsConMap(Object, @JsonType)
  Found = @false
  ForEach Key In TypesMap
     If TypesMap[Key] == @JsonObj
        Found = @true
        Break
     EndIf
  Next
  ; Found a nested JSON object?
  If Found Then Text = 'Nested object found with the key name of "':Key:'"'
  Else Text = 'No nested objects'
  Message('Nested Object Search', Text)
  jsConClose()
  
See Also:

jsParse, jsConNew, jsValueType, jsValueGet