Dictionary Function
This section describes dictionary functions, including their syntax, parameters, and usage examples.
Function List
Function |
Description |
---|---|
Creates a dictionary. |
|
Updates a dictionary. |
|
Deletes dictionary key-value pairs. |
|
Obtains the key list of a dictionary. |
|
Obtains the dictionary value list. |
|
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"}
- Test data
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"}
- Test data
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"}
- Test data
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"]
- Test data
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"]
- Test data
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
- 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
- Test data
- 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
- Test data
- Example 1:
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot