This topic describes the syntax and parameters of dictionary functions. This topic also provides examples on how to use the functions.

Functions

Function Description
dct_make Constructs a dictionary.
dct_update Updates a dictionary.
dct_delete Deletes key-value pairs from a dictionary.
dct_keys Obtains the keys of a dictionary.
dct_values Obtains the values of a dictionary.
dct_get Obtains the value that corresponds to a specified key in a dictionary.
op_len Obtains the number of elements in a dictionary.

dct_make

  • Syntax
    dct_make(Key 1, Value 1, Key 2, Value 2, ...)
    Note The Key and Value parameters must be specified in pairs.
  • Parameters
    Parameter Type Required Description
    Key String Yes The key in the dictionary that you want to construct.
    Value Arbitrary Yes The value in the dictionary that you want to construct.
  • Response

    The constructed dictionary is returned.

  • Example
    Transformation rule:
    e_set("hello", dct_make("k1","v1","k2","v2"))
    Result:
    hello: {"k1":"v1","k2":"v2"}

dct_update

  • Syntax
    dct_update(Dictionary 1, Dictionary 2)
  • Parameters
    Parameter Type Required Description
    Dictionary 1 dict Yes The dictionary that you want to update.
    Dictionary 2 dict Yes The dictionary that is used to update the specified dictionary.
  • Response

    The updated dictionary is returned.

  • Example
    Raw log entry:
    ctx: {"k1":"v1","k2":"v2"}
    Transformation rule:
    e_set("hello", dct_update(v("ctx"), {"k3": "v3"}))
    Result:
    ctx: {"k1":"v1","k2":"v2"}
    hello: {"k1": "v1", "k2": "v2", "k3": "v3"}

dct_delete

  • Syntax
    dct_delete(Dictionary, Key 1, Key 2, ...)
  • Parameters
    Parameter Type Required Description
    Dictionary dict Yes The dictionary from which you want to delete specific key-value pairs.
    Key 1 String Yes The key of the key-value pair that you want to delete from the dictionary.
    Key 2 String No The key of the key-value pair that you want to delete from the dictionary.
  • Response

    The dictionary from which the specified key-value pairs are deleted is returned.

  • Example
    Raw log entry:
    ctx: {"k1":"v1","k2":"v2"}
    Transformation rule:
    e_set("hello", dct_delete(v("ctx"), "k2"))
    Result:
    ctx: {"k1":"v1","k2":"v2"}
    hello: {"k1":"v1"}

dct_keys

  • Syntax
    dct_keys(Dictionary)
  • Parameters
    Parameter Type Required Description
    Dictionary dict Yes The dictionary from which you want to obtain keys.
  • Response

    The keys of the dictionary are returned.

  • Example
    Raw log entry:
    ctx: {"k1":"v1","k2":"v2"}
    Transformation rule:
    e_set("hello", dct_keys(v("ctx")))
    Result:
    ctx: {"k1":"v1","k2":"v2"}
    hello: ["k1","k2"]

dct_values

  • Syntax
    dct_values(Dictionary)
  • Parameters
    Parameter Type Required Description
    Dictionary dict Yes The dictionary from which you want to obtain keys.
  • Response

    The values of the dictionary are returned.

  • Example
    Raw log entry:
    ctx: {"k1":"v1","k2":"v2"}
    Transformation rule:
    e_set("hello", dct_values(v("ctx")))
    Result:
    ctx: {"k1":"v1","k2":"v2"}
    hello: ["v1","v2"]

dct_get

  • Syntax
    dct_get(Dictionary,key,default=None)
  • Parameters
    Parameter Type Required Description
    Dictionary dict Yes The dictionary from which you want to obtain the value that corresponds to a specified key.
    key Arbitrary Yes The key whose value you want to obtain.
    default Arbitrary No If the specified key does not exist, the value of the default parameter is returned.
  • Response

    The value that corresponds to a specified key in a dictionary is returned.

  • Examples
    • Example 1
      Raw log entry:
      ctx: {"k1":"v1","k2":"v2"}
      Transformation rule:
      e_set("hello", dct_get(v("ctx"), "k1"))
      Result:
      ctx: {"k1":"v1","k2":"v2"}
      hello: v1
    • Example 2: The specified key does not exist and the value of the default parameter is returned.
      Raw log entry:
      ctx: {"k1":"v1","k2":"v2"}
      Transformation rule:
      e_set("hello", dct_get(v("ctx"), "k3",default="123"))
      Result:
      ctx: {"k1":"v1","k2":"v2"}
      hello: 123