tencent cloud

Cloud Log Service

Encoding and Decoding Functions

Download
Focus Mode
Font Size
Last updated: 2025-04-30 09:45:11

Function decode_url

Function definition

This function is used to decode an encoded URL.

Syntax description

decode_url(value)

Parameter description

Parameter
Description
Type
Required
Default Value
Value Range
url
URL value
string
Yes
-
-

Sample

Raw log:
{"url":"https%3A%2F%2Fcloud.tencent.com%2F"}
Processing rule:
fields_set("result",decode_url(v("url")))
Processing result:
{"result":"https://cloud.tencent.com/","url":"https%3A%2F%2Fcloud.tencent.com%2F"}

Function md5_encoding

Function definition

This function is used to calculate and return the MD5 checksum.

Syntax description

md5_encoding(value)

Parameter description

Parameter
Description
Type
Required
Default Value
Value Range
Value
The data for which to calculate the MD5 checksum
String
Yes
-
-

Sample

Raw log:
{"field": "haha"}
Processing rule:
fields_set("field", md5_encoding(v("field")))
Processing result:
{"field":"4e4d6c332b6fe62a63afe56171fd3725"}

Function uuid

Function definition

This function is used to generate a universally unique identifier (UUID).

Syntax description

uuid()

Parameter description

No input parameters

Sample

Raw log:
{"key":"value"}
Processing rule:
fields_set("field",uuid())
Processing result:
{"field":"8c2db704-45c0-4ea1-9e2c-cf9c966e35cd","key":"value"}

Function str_encode

Function definition

Encode a string in the specified format.

Syntax description

str_encode(data, encoding="utf8", errors="ignore")

Parameter description

Parameter
Description
Type
Required
Default Value
Value Range
data
Data to be encoded
String
Yes
-
-
encoding
Encoding format, utf8 by default, supporting ASCII, latin1, and unicode-escape.
String
No
utf8
-
errors
Handling method when encoding format cannot recognize characters:
ignore (default): Ignore and do not encode.
Strict control: Report an error directly and discard this log data.
replace: Use a half-angle question mark (?), and replace the unrecognized part.
xmlcharrefreplace: Use corresponding XML character references to replace unrecognized parts
String
No
ignore
-

Sample

Raw log:
{"field1": "asd encode encode \\\\u1234"}
Processing rule:
fields_set("field2", str_decode(str_encode(v("field1"), "unicode-escape"), "unicode-escape"))
Processing result:
{"field1":"asd encode encode \\\\u1234","field2":"asd code code ሴ"}

Function Str_decode

Function definition

Decode a string in the specified format.

Syntax description

str_decode(data, encoding="utf8", errors="ignore")

Parameter description

Parameter
Description
Type
Required
Default Value
Value Range
data
Data to be decoded
String
Yes
-
-
encoding
Encoding format, utf8 by default, supporting ASCII, latin1, and unicode-escape.
String
No
utf8
-
errors
Handling method when encoding format cannot recognize characters:
ignore (default): Ignore and do not decode.
Strict control: Report an error directly and discard this log data.
replace: Replace the undecodable part with a half-width question mark (?).
xmlcharrefreplace: Use corresponding XML characters to replace undecodable parts
String
No
ignore
-

Sample

Raw log:
{"field1": "Test in English and Chinese: qwertyuiopasdfghjklzxcvbnm QWERTYUIOPASDFGHJKLZXCVBNM special symbols:]] [! @#$%^&*()_++~"}
Processing rule:
fields_set("field2", str_decode(str_encode(v("field1"))))
Processing result:
{"field1":"Test in English and Chinese: qwertyuiopasdfghjklzxcvbnm QWERTYUIOPASDFGHJKLZXCVBNM Special Symbols:]] [! @#$%^&*()_++~", "field2":"Test in English and Chinese: qwertyuiopasdfghjklzxcvbnm QWERTYUIOPASDFGHJKLZXCVBNM special symbols:]] [! @#$%^&*()_++~"}

Function Base64 Encode

Function definition

Encode the string in base64.

Syntax description

base64_encode(value, format="RFC3548")

Parameter description

Parameter
Description
Type
Required
Default Value
Value Range
value
String to be encoded
string
Yes
-
-
format
Encoding format, supports RFC4648 (default), RFC3548
string
No
RFC4648
-

Sample

Raw log:
{"field": "hello world"}
Processing rule:
fields_set("encode", base64_encode(v("field")))
Processing result:
{"encode":"aGVsbG8gd29ybGQ=", "field":"hello world"}

Function Base64 Decode

Function definition

Decode the string in base64.

Syntax description

base64_decode(value, format="RFC3548")

Parameter description

Parameter
Description
Type
Required
Default Value
Value Range
value
The string to be decoded
string
Yes
-
-
format
Decoding format, supports RFC4648 (default), RFC3548
string
No
RFC4648
-

Sample

Raw log:
{"field": "aGVsbG8gd29ybGQ="}
Processing rule:
fields_set("decode", base64_decode(v("field")))
Processing result:
{"decode":"hello world", "field":"aGVsbG8gd29ybGQ="}


Help and Support

Was this page helpful?

Help us improve! Rate your documentation experience in 5 mins.

Feedback