Updated on 2025-09-07 GMT+08:00

Dictionary Function

This section describes dictionary functions, including their syntax, parameters, and usage examples.

Function List

Function

Description

dct_make

Creates a dictionary.

dct_update

Updates a dictionary.

dct_delete

Deletes dictionary key-value pairs.

dct_keys

Obtains the key list of a dictionary.

dct_values

Obtains the dictionary value list.

dct_get

Obtains the value of a key in a dictionary.

dct_make

Use the dct_make function to create a dictionary.

  • Function format
    dct_make(key1, value1, key2, value2, ...)
  • Parameter description

    Parameter

    Type

    Mandatory

    Description

    key

    String

    Yes

    Character string used as the dictionary key.

    value

    String

    Yes

    Character string used as the dictionary value.

  • Returned result

    Constructed dictionary.

  • Function example
    • Test data
      {
        "content": "test"
      }
    • Processing rule
      e_set("hello", dct_make("k1","v1","k2","v2"))
    • Processing result
      content:test
      hello:{"k1": "v1", "k2": "v2"}

dct_update

Use the dct_update function to update a dictionary.

  • Function format
    dct_update(dict1, dict2)
  • Parameter description

    Parameter

    Type

    Mandatory

    Description

    dict1

    dict

    Yes

    Target dictionary to be updated.

    dict2

    dict

    Yes

    New dictionary to be added.

  • Returned result

    Updated dictionary.

  • Function example
    • Test data
      { 
        "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

Use the dct_delete function to delete dictionary key-value pairs.

  • Function format
    dct_delete(dict, key1, key2, ...)
  • Parameter description

    Parameter

    Type

    Mandatory

    Description

    dict

    dict

    Yes

    Target dictionary whose key-value pairs need to be deleted.

    key1

    String

    Yes

    Key of the key-value pair to be deleted.

    key2

    String

    No

    Key of the key-value pair to be deleted.

  • Returned result

    Dictionary after the deletion.

  • Function example
    • Test data
      { 
        "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

Use the dct_keys function to obtain the key list of a dictionary.

  • Function format
    dct_keys(dict)
  • Parameter description

    Parameter

    Type

    Mandatory

    Description

    dict

    dict

    Yes

    Dictionary data.

  • Returned result

    List of dictionary keys.

  • Function example
    • Test data
      { 
        "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

Use the dct_values function to obtain the dictionary value list.

  • Function format
    dct_values(dict)
  • Parameter description

    Parameter

    Type

    Mandatory

    Description

    dict

    dict

    Yes

    Dictionary data.

  • Returned result

    List of dictionary values.

  • Function example
    • Test data
      { 
        "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

Use the dct_get function to obtain the value of a key in a dictionary.

  • Function format
    dct_get(dict,key,default=None)
  • Parameter description

    Parameter

    Type

    Mandatory

    Description

    dict

    dict

    Yes

    Dictionary data.

    key

    String

    Yes

    Key of the value to be obtained.

    default

    String

    No

    If the key does not exist, this value is returned.

  • Returned result

    Value of a dictionary key.

  • Function example
    1. Example 1:
      • Test data
        { 
          "ctx": "{\"k1\":\"v1\",\"k2\":\"v2\"}" 
        }
      • Processing rule
        e_set("hello", dct_get(v("ctx"), "k1"))
      • Processing result
        ctx: {"k1":"v1","k2":"v2"}
        hello: v1
    2. Example 2:
      • Test data
        { 
          "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