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 Returns the keys of a dictionary.
dct_values Returns the values of a dictionary.
dct_get Returns the value that corresponds to a specified key in a dictionary.
op_len Returns the number of elements in a dictionary.

dct_make

The dct_make function constructs a dictionary.
  • Syntax

    dct_make(key1, value1, key2, value2, ...)
    Note You must specify the key and value parameters in pairs.
  • Parameters

    Parameter Type Required Description
    key String Yes The key in the dictionary that you want to construct.
    value String Yes The value in the dictionary that you want to construct.
  • Response

    The constructed dictionary is returned.

  • Examples

    • Raw log
      content:test
    • Transformation rule
      e_set("hello", dct_make("k1","v1","k2","v2"))
    • Result
      content:test
      hello:{"k1": "v1", "k2": "v2"}

dct_update

The dct_update function updates a dictionary.
  • Syntax

    dct_update(dict1, dict2)
  • Parameters

    Parameter Type Required Description
    dict1 dict Yes The dictionary that you want to update.
    dict2 dict Yes The dictionary information that is added to the specified dictionary.
  • Response

    The updated dictionary is returned.

  • Examples

    • Raw log
      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

The dct_delete function deletes key-value pairs from a dictionary.
  • Syntax

    dct_delete(dict, key1, key2, ...)
  • Parameters

    Parameter Type Required Description
    dict dict Yes The dictionary from which you want to delete the specified key-value pair.
    key1 String Yes The key of the key-value pair that you want to delete from the dictionary.
    key2 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 pair is deleted is returned.

  • Examples

    • Raw log
      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

The dct_keys function returns the keys of a dictionary.
  • Syntax

    dct_keys(dict)
  • Parameters

    Parameter Type Required Description
    dict dict Yes The dictionary from which you want to obtain the keys.
  • Response

    The keys of the dictionary are returned.

  • Examples

    • Raw log
      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

The dct_values function returns the values of a dictionary.
  • Syntax

    dct_values(dict)
  • Parameters

    Parameter Type Required Description
    dict dict Yes The dictionary from which you want to obtain the values.
  • Response

    The values of the dictionary are returned.

  • Examples

    • Raw log
      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

The dct_get function returns the value that corresponds to a specified key in a dictionary.
  • Syntax

    dct_get(dict,key,default=None)
  • Parameters

    Parameter Type Required Description
    dict dict Yes The dictionary from which you want to obtain the value of the specified key.
    key String Yes The key whose value you want to obtain.
    default String No The value that is returned if the specified key does not exist.
  • Response

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

  • Examples

    • Example 1
      • Raw log
        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. The value of the default parameter is returned.
      • Raw log
        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