This topic describes the syntax of dictionary functions and provides parameter description and function examples.

Functions

Type Function Description
Dictionary processing dct_make Constructs a dictionary.
dct_update Updates a dictionary.
dct_delete Deletes entries from a dictionary.
dct_keys Obtains keys of a dictionary.
dct_values Obtains values of a dictionary.
dct_get Obtains the value corresponding to a key in a dictionary.

dct_make

  • Syntax
    dct_make(Key 1, Value 1, Key 2, Value 2, ...)
    Note The Key and Value parameters must appear in pairs.
  • Parameters
    Parameter Type Required? Description
    Key String Yes The key in the dictionary.
    Value Any type Yes The value in the dictionary.
  • Response

    The constructed dictionary is returned.

  • Examples
    Processing rule:
    e_set("hello", dct_make("k1","v1","k2","v2"))
    Processing result:
    hello: {"k1":"v1","k2":"v2"}

dct_update

  • Syntax
    dct_update(Dictionary 1, Dictionary 2)
  • Parameters
    Parameter Type Required? Description
    Dictionary 1 Dictionary Yes The dictionary to update.
    Dictionary 2 Dictionary Yes The dictionary used to update the other dictionary.
  • Response

    The updated dictionary is returned.

  • Examples
    Raw log:
    ctx: {"k1":"v1","k2":"v2"}
    Processing rule:
    e_set("hello", dct_update(v("ctx"), {"k3": "v3"}))
    Processing 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 Dictionary Yes The dictionary from which you want to delete specified keys.
    Key 1 String Yes The key to delete from the dictionary.
    Key 2 String No The key to delete from the dictionary.
  • Response

    The updated dictionary is returned.

  • Examples
    Raw log:
    ctx: {"k1":"v1","k2":"v2"}
    Processing rule:
    e_set("hello", dct_delete(v("ctx"), "k2"))
    Processing result:
    ctx: {"k1":"v1","k2":"v2"}
    hello: {"k1":"v1"}

dct_keys

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

    The keys in the dictionary are returned.

  • Examples
    Raw log:
    ctx: {"k1":"v1","k2":"v2"}
    Processing rule:
    e_set("hello", dct_keys(v("ctx")))
    Processing result:
    ctx: {"k1":"v1","k2":"v2"}
    hello: ["k1","k2"]

dct_values

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

    The values in the dictionary are returned.

  • Examples
    Raw log:
    ctx: {"k1":"v1","k2":"v2"}
    Processing rule:
    e_set("hello", dct_values(v("ctx")))
    Processing result:
    ctx: {"k1":"v1","k2":"v2"}
    hello: ["v1","v2"]

dct_get

  • Syntax
    dct_get(Dictionary,key,default=None)
  • Parameters
    Parameter Type Required? Description
    Dictionary Dictionary Yes The dictionary from which you want to obtain the value corresponding to the specified key.
    key Any type Yes The key whose value is to be obtained.
    default Any type No The default value to return if the key does not exist.
  • Response

    The value of a dictionary key is returned.

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