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

Encoding and Decoding Function

This section describes the encoding and decoding functions, including their syntax, parameters, and usage examples.

Function List

Type

Category

Function

Description

Encode/Decode

String

str_encode

Encodes data.

str_decode

Decodes data.

Base64

base64_encoding

Encodes data using Base64.

base64_decoding

Decodes data using Base64.

HTML

html_encoding

Encodes data using HTML.

html_decoding

Decodes data using HTML.

URL

url_encoding

Encodes data using URL.

url_decoding

Decodes data using URL.

Compression/Decompression

Gzip compression library

gzip_compress

Compresses and encodes data.

gzip_decompress

Decompresses data.

Zlib compression library

zlib_compress

Compresses and encodes data.

zlib_decompress

Decompresses data.

Hash digest

MD5

md5_encoding

Encodes data using MD5.

SHA1

sha1_encoding

Encodes data using SHA1.

Cyclic redundancy check

crc32_encoding

Calculates the cyclic redundancy check code of the data.

str_encode

Use the str_encode function to encode a string in a specified encoding format.

  • Function format
    str_encode(value, "utf8", errors="ignore")
  • Parameter description

    Parameter

    Type

    Mandatory

    Description

    value

    Any (automatically converted to string)

    Yes

    Value to be encoded.

    encoding

    String

    No

    Encoding format. The default format is UTF-8. ASCII is supported.

    errors

    String

    No

    Specifies the processing solution when characters cannot be identified according to the encoding format. Options:

    • ignore (default): Ignore the characters that cannot be identified.
    • strict: An error is reported and the log data is discarded.
    • replace : The unidentified part is replaced with the question mark (?).
    • xmlcharrefreplace: The unidentified part is replaced with the corresponding XML character.
  • Returned result

    Encoded string.

  • Function example
    1. Example 1
      • Test data
        {
          "value": "test test"
        }
      • Processing rule
        e_set("result", str_encode(v("value"), "ascii", errors="ignore"))
      • Processing result
          "value": "test"
        result: test 
    2. Example 2
      • Test data
        {
          "value": "test test"
        }
      • Processing rule
        e_set("result", str_encode(v("value"), "ascii", errors="strict"))
      • Processing result: An error is reported during execution.
    3. Example 3
      • Test data
        {
          "value": "test test"
        }
      • Processing rule
        e_set("result", str_encode(v("value"), "ascii", errors="replace"))
      • Processing result
        value: test test
        result: test ??
    4. Example 4
      • Test data
        {
          "value": "test test"
        }
      • Processing rule
        e_set("result", str_encode(v("value"), "ascii", errors="xmlcharrefreplace"))
      • Processing result
        value: test test
        result: test 测试

str_decode

Use the str_decode function to decode the input value in a specified encoding format.

  • Function format
    str_decode(value, "utf8", errors="ignore")
  • Parameter description

    Parameter

    Type

    Mandatory

    Description

    value

    Any (automatically converted to string)

    Yes

    Value to be decoded.

    encoding

    Any (automatically converted to string)

    No

    Encoding format. The default format is UTF-8. ASCII is supported.

    errors

    Any (automatically converted to string)

    No

    Specifies the processing solution when characters cannot be identified according to the encoding format. Options:

    • ignore (default): Ignore the characters that cannot be decoded.
    • strict: An error is reported and the log data is discarded.
    • replace : Replace the part that cannot be decoded with the question mark (?).
    • xmlcharrefreplace: Replace the part that cannot be decoded with the corresponding XML character.
  • Returned result

    Decoded value.

  • Function example
    • Test data
      {
        "test": "asewds"
      }
    • Processing rule
      e_set("encoding", str_decode(b'\xe4\xbd\xa0\xe5\xa5\xbd', "utf8", 'strict'))
    • Processing result
      test: asewds 
      encoding: Hello

base64_encoding

Use the base64_encoding function to encode data using Base64.

  • Function format
    base64_encoding(value, format=None)
  • Parameter description

    Parameter

    Type

    Mandatory

    Description

    value

    String

    Yes

    Value to be encoded.

    format

    String

    No

    Base64 encoding protocol. The default value is format=RFC3548. You can also set it to format=RFC4648.

  • Returned result

    Encoded string.

  • Function example
    • Test data
      {
        "str_en": "data to be encoded"
      }
    • Processing rule
      e_set("str_base64",base64_encoding(v("str_en")))
    • Processing result
      str_en : data to be encoded 
      str_base64 : ZGF0YSB0byBiZSBlbmNvZGVk

base64_decoding

Use the base64_decoding function to decode data using Base64.

  • Function format
    base64_decoding(value, format=None)
  • Parameter description

    Parameter

    Type

    Mandatory

    Description

    value

    String

    Yes

    Value to be decoded.

    format

    String

    No

    Base64 decoding protocol. The default value is format=RFC3548. You can also set it to format=RFC4648.

    RFC4648 Base64 decoding protocol uses equal signs (=) to pad the value to be decoded to a multiple of 4 bytes.

  • Returned result

    Decoded string.

  • Function example
    • Test data
      {
        "str_de": "ZGF0YSB0byBiZSBlbmNvZGVk"
      }
    • Processing rule
      e_set("str_de_base64",base64_decoding(v("str_de")))
    • Processing result
      str_de: ZGF0YSB0byBiZSBlbmNvZGVk 
      str_de_base64: data to be encoded

html_encoding

Use the html_encoding function to encode data using HTML.

  • Function format
    html_encoding(value)
  • Parameter description

    Parameter

    Type

    Mandatory

    Description

    value

    String

    Yes

    Value to be encoded.

  • Returned result

    Encoded string.

  • Function example
    • Test data
      { 
        "str":"<img class=\"size-medium wp-image-113\" style=\"margin-left: 15px;\" title=\"su1\" src=\"http://aadoc.com/wp-content/uploads/2008/10/su1-300x194.jpg\" alt=\"\" width=\"300\" height=\"194\" />" 
      }
    • Processing rule
      e_set("str_html_en",html_encoding(v("str")))
    • Processing result
      str : <img class="size-medium wp-image-113" style="margin-left: 15px;" title="su1" src="http://aadoc.com/wp-content/uploads/2008/10/su1-300x194.jpg" alt="" width="300" height="194" />
      str_html_en : &lt;img class=&quot;size-medium wp-image-113&quot; style=&quot;margin-left: 15px;&quot; title=&quot;su1&quot; src=&quot;http://aadoc.com/wp-content/uploads/2008/10/su1-300x194.jpg&quot; alt=&quot;&quot; width=&quot;300&quot; height=&quot;194&quot; /&gt;

html_decoding

Use the html_decoding function to decode data using HTML.

  • Function format
    html_decoding(value)
  • Parameter description

    Parameter

    Type

    Mandatory

    Description

    value

    String

    Yes

    Value to be decoded.

  • Returned result

    Decoded string.

  • Function example
    • Test data
      {
        "str": "&lt;img class=&quot;size-medium wp-image-113&quot; style=&quot;margin-left: 15px;&quot; title=&quot;su1&quot; src=&quot;http://aadoc.com/wp-content/uploads/2008/10/su1-300x194.jpg&quot; alt=&quot;&quot; width=&quot;300&quot; height=&quot;194&quot; /&gt;"
      }
    • Processing rule
      e_set("str_html_de",html_decoding(v("str")))
    • Processing result
      str : <img class="size-medium wp-image-113" style="margin-left: 15px;" title="su1" src="http://aadoc.com/wp-content/uploads/2008/10/su1-300x194.jpg" alt="" width="300" height="194" />
      str_html_de: <img class="size-medium wp-image-113" style="margin-left: 15px;" title="su1" src="http://aadoc.com/wp-content/uploads/2008/10/su1-300x194.jpg" alt="" width="300" height="194" />

url_encoding

Use the url_encoding function to encode data using URL.

  • Function format
    url_encoding(value, plus=false)
  • Parameter description

    Parameter

    Type

    Mandatory

    Description

    value

    String

    Yes

    Value to be encoded.

    plus

    Boolean

    No

    Whether to convert a space to a plus sign (+). The default value is false.

    • true: Convert a space to a plus sign (+).
    • false: Do not convert a space to a plus sign (+).
  • Returned result

    Encoded string.

  • Function example
    1. Example 1: Perform URL encoding on data.
      • Test data
        {
          "content": "https://www.example.org/hello/asdah"
        }
      • Processing rule
        e_set("url",url_encoding(v("content")))
      • Processing result
        content : https://www.example.org/hello/asdah
        url: https%3A%2F%www.example.org%2FHello%2Fasdah
    2. Example 2: Perform URL encoding on data. If the parameter plus is not specified, the space in the data is not converted to a plus sign (+).
      • Test data
        {
          "content": "1 2+3:4"
        }
      • Processing rule
        e_set("URL",url_encoding(v("content")))
      • Processing result
        content:1 2+3:4 
        URL:1%202%2B3%3A4
    3. Example 3: Perform URL encoding on data. If the parameter plus is set to true, the space in the data is converted to a plus sign (+).
      • Test data
        {
          "content": "1 2+3:4"
        }
      • Processing rule
        e_set("URL", url_encoding(v("content"), plus=true))
      • Processing result
        content:1 2+3:4
        URL:1+2%2B3%3A4

url_decoding

Use the url_decoding function to decode data using URL.

  • Function format
    url_decoding(value, plus=false)
  • Parameter description

    Parameter

    Type

    Mandatory

    Description

    value

    String

    Yes

    Value to be decoded.

    plus

    Boolean

    No

    Whether to convert plus signs (+) to spaces. The default value is false.

    • true: Convert plus signs (+) to spaces.
    • false: Do not convert plus signs (+) to spaces.
  • Returned result

    Decoded string.

  • Function example
    1. Example 1: Perform URL decoding on data.
      • Test data
        {
          "content": "https%3A%2F%www.example.org%2FHello%2Fasdah"
        }
      • Processing rule
        e_set("URL",url_decoding(v("content")))
      • Processing result
        content : https%3A%2F%www.example.org%2FHello%2Fasdah 
        URL : https://www.example.org/hello/asdah
    2. Example 2: Perform URL decoding on data. If the parameter plus is not specified, the plus sign (+) in the data is not converted to space.
      • Test data
        {
          "content": "/answer?event_date=2022-06-30+09%3A06%3A53%20123"
        }
      • Processing rule
        e_set("URL",url_decoding(v("content")))
      • Processing result
        content:/answer?event_date=2022-06-30+09%3A06%3A53%20123
        URL:/answer?event_date=2022-06-30+09:06:53 123
    3. Example 3: Perform URL decoding on data. If the parameter plus is set to true, the plus sign (+) in the data is converted to space.
      • Test data
        {
          "content": "/answer?event_date=2022-06-30+09%3A06%3A53%20123"
        }
      • Processing rule
        e_set("URL",url_decoding(v("content"),plus=true))
      • Processing result
        content:/answer?event_date=2022-06-30+09%3A06%3A53%20123
        URL:/answer?event_date=2022-06-30 09:06:53 123

gzip_compress

Use the gzip_compress function to compress and encode data.

  • Function format
    gzip_compress(data, compresslevel=6, to_format="base64", encoding="utf-8")
  • Parameter description

    Parameter

    Type

    Mandatory

    Description

    data

    String

    Yes

    Data to be compressed.

    compresslevel

    Int

    No

    Specifies the compression level. The value is an integer ranging from 0 to 9. The default value is 6.

    • 1: The compression speed is the fastest, but the compression ratio is the smallest.
    • 9: The compression speed is the slowest, but the compression ratio is the largest.
    • 0: no compression.

    to_format

    String

    No

    Specifies the encoding format of the compressed data. Currently, Base64 and hex encoding are supported.

    encoding

    String

    No

    Encoding format of the original uncompressed data. The default value is utf-8.

  • Returned result

    Encoded string.

  • Function example (for reference only)
    1. Example 1: Compress log fields and encode them using Base64.
      • Test data
        {
          "content":"I always look forward to my holidays whether I travel or stay at home."
        }
      • Processing rule
        e_set("base64_encode_gzip_compress",gzip_compress(v("content"),to_format="base64"))
      • Processing result
        content: I always look forward to my holidays whether I travel or stay at home. base64_encode_gzip_compress: H4sIAA8JXl4C/xXK0QmAMAwFwFXeBO7RMQKNREx5kAZDtle/7wbES3rDyRsnoyQmklgNo1/ztzJN08BAhjzqYGCnNCS/tPR4AcgrnWVGAAAA
    2. Example 2: Encode log fields using hex format.
      • Test data
        {
           "content":"H4sIAA8JXl4C/xXK0QmAMAwFwFXeBO7RMQKNREx5kAZDtle/7wbES3rDyRsnoyQmklgNo1/ztzJN08BAhjzqYGCnNCS/tPR4AcgrnWVGAAAA"
        }
      • Processing rule
        e_set("hex_encode_gzip_compress", gzip_compress(v("content"), to_format="hex"))
      • Processing result
        content:H4sIAA8JXl4C/xXK0QmAMAwFwFXeBO7RMQKNREx5kAZDtle/7wbES3rDyRsnoyQmklgNo1/ztzJN08BAhjzqYGCnNCS/tPR4AcgrnWVGAAAA hex_encode_gzip_compress:1f8b08004a478c6202ff0dc1dd0e43301800d047aa65156e3ff52f4a2ba17649c43255194d4a9f9e73527c64007e2e2426e81485c35628c1c42616535079bc6405e5d1e92ef009b59c906786a879efe1c50fb55d6c5de44cb717b2dae6d4f103f8feecbf4f88a2a441bae618c679575d9bc0e306907876806c000000

gzip_decompress

Use the gzip_decompress function to decompress data.

  • Function format
    gzip_decompress(data, from_format="base64", encoding="utf-8")
  • Parameter description

    Parameter

    Type

    Mandatory

    Description

    data

    Any

    Yes

    Data to be decompressed.

    from_format

    String

    No

    Encoding format of the data to be decompressed. Currently, Base64 and hex formats are supported.

    encoding

    String

    No

    Encoding format of the original uncompressed data. The default value is utf-8. For other encoding formats, see standard encoding formats.

  • Returned result

    Decompressed data.

  • Function example
    1. Example 1: Decode log fields using Base64.
      • Test data
        {
          "content": "H4sIAA8JXl4C/xXK0QmAMAwFwFXeBO7RMQKNREx5kAZDtle/7wbES3rDyRsnoyQmklgNo1/ztzJN08BAhjzqYGCnNCS/tPR4AcgrnWVGAAAA"
        }
      • Processing rule
        e_set("gzip_decompress",gzip_decompress(v("content"),from_format="base64"))
      • Processing result
        content: H4sIAA8JXl4C/xXK0QmAMAwFwFXeBO7RMQKNREx5kAZDtle/7wbES3rDyRsnoyQmklgNo1/ztzJN08BAhjzqYGCnNCS/tPR4AcgrnWVGAAAA gzip_decompress: I always look forward to my holidays whether I travel or stay at home.
    2. Example 2: Decode log fields using hex format.
      • Test data
        {
        "content":"1f8b0800bff8856202ff0dc1dd0e43301800d047aa65156e3ff52f4a2ba17649c43255194d4a9f9e73527c64007e2e2426e81485c35628c1c42616535079bc6405e5d1e92ef009b59c906786a879efe1c50fb55d6c5de44cb717b2dae6d4f103f8feecbf4f88a2a441bae618c679575d9bc0e306907876806c000000"
        }
      • Processing rule
        e_set("gzip_decompress", gzip_decompress(v("content"), from_format="hex"))
      • Processing result
        content:1f8b0800bff8856202ff0dc1dd0e43301800d047aa65156e3ff52f4a2ba17649c43255194d4a9f9e73527c64007e2e2426e81485c35628c1c42616535079bc6405e5d1e92ef009b59c906786a879efe1c50fb55d6c5de44cb717b2dae6d4f103f8feecbf4f88a2a441bae618c679575d9bc0e306907876806c000000 gzip_decompress:H4sIAA8JXl4C/xXK0QmAMAwFwFXeBO7RMQKNREx5kAZDtle/7wbES3rDyRsnoyQmklgNo1/ztzJN08BAhjzqYGCnNCS/tPR4AcgrnWVGAAAA

zlib_compress

Use the zlib_compress function to compress and encode data.

  • Function format

    zlib_compress(data, compresslevel=6, to_format="base64", encoding="utf-8")

  • Parameter description

    Parameter

    Type

    Mandatory

    Description

    data

    String

    Yes

    Data to be compressed.

    compresslevel

    Int

    No

    Specifies the compression level. The value is an integer ranging from 0 to 9. The default value is 6.

    • 1: The compression speed is the fastest, but the compression ratio is the smallest.
    • 9: The compression speed is the slowest, but the compression ratio is the largest.
    • 0: no compression.

    to_format

    String

    No

    Specifies the format for encoding compressed data. Currently, only Base64 encoding is supported.

    encoding

    String

    No

    Encoding format of the original uncompressed data. The default value is utf-8.

  • Returned result

    Encoded data.

  • Function example
    • Test data
      {
         "content":"I always look forward to my holidays whether I travel or stay at home."
      }
    • Processing rule
      e_set("zlib_compress", zlib_compress(v("content"), to_format="base64"))
    • Processing result (for reference only)
      zlib_compress: eJwVytEJgDAMBcBV3gTu0TECjURMeZAGQ7ZXv+8GxEt6w8kbJ6MkJpJYDaNf87cyTdPAQIY86mBgpzQkv7T0eAGNshln
      content: I always look forward to my holidays whether I travel or stay at home.

zlib_decompress

  • Function format
    zlib_decompress(data, from_format="base64", encoding="utf-8")
  • Parameter description

    Parameter

    Type

    Mandatory

    Description

    data

    String

    Yes

    Data to be decompressed.

    from_format

    String

    No

    Encoding format of the decompressed data. Currently, only Base64 encoding is supported.

    encoding

    String

    No

    Encoding format. The default format is UTF-8.

  • Returned result

    Decompressed data.

  • Function example
    • Test data
      {
        "content": "eJwVytEJgDAMBcBV3gTu0TECjURMeZAGQ7ZXv+8GxEt6w8kbJ6MkJpJYDaNf87cyTdPAQIY86mBgpzQkv7T0eAGNshln"
      }
    • Processing rule
      e_set("zlib_decompress", zlib_decompress(v("content"), from_format="base64"))
    • Processing result
      content: eJwVytEJgDAMBcBV3gTu0TECjURMeZAGQ7ZXv+8GxEt6w8kbJ6MkJpJYDaNf87cyTdPAQIY86mBgpzQkv7T0eAGNshln
      zlib_decompress: I always look forward to my holidays whether I travel or stay at home.

md5_encoding

Use the md5_encoding function to encode data using MD5.

  • Function format
    md5_encoding(value, format="hex")
  • Parameter description

    Parameter

    Type

    Mandatory

    Description

    value

    String

    Yes

    Value to be encoded.

    format

    String

    No

    Options: binary and hex (default).

  • Returned result

    Encoded string.

  • Function example
    1. Example 1
      • Test data
        {
          "str": "GeeksforGeeks"
        }
      • Processing rule
        e_set("str_md5_en",md5_encoding(v("str")))
      • Processing result
        str : GeeksforGeeks
        str_md5_en : f1e069787ece74531d112559945c6871
    2. Example 2
      • Test data
        {
          "str": "GeeksforGeeks"
        }
      • Processing rule
        e_set("str_md5_en",base64_encoding(md5_encoding(v("str"), format="binary")))
      • Processing result
        str : GeeksforGeeks
        str_md5_en : 8eBpeH7OdFMdESVZlFxocQ==

sha1_encoding

Use the sha1_encoding function to encode data using SHA-1.

  • Function format
    sha1_encoding(value, format=None)
  • Parameter description

    Parameter

    Type

    Mandatory

    Description

    value

    String

    Yes

    Value to be encoded.

    format

    String

    No

    Encoding type. Options: SHA1 (default), SHA-256, SHA384, SHA224, SHA512.

  • Returned result

    Encoded string.

  • Function example
    • Test data
      {
        "str": "GeeksforGeeks"
      }
    • Processing rule
      e_set("str_sha1",sha1_encoding(v("str")))
      e_set("str_sha512",sha1_encoding(v("str"),format='SHA512'))
      e_set("str_sha224",sha1_encoding(v("str"),format='SHA224'))
      e_set("str_sha384",sha1_encoding(v("str"),format=)))
      e_set("str_sha256",sha1_encoding(v("str"),format='SHA256'))
    • Processing result
      str : GeeksforGeeks 
      str_sha1 : 4175a37afd561152fb60c305d4fa6026b7e79856 
      str_sha512 : 0d8fb9370a5bf7b892be4865cdf8b658a82209624e33ed71cae353b0df254a75db63d1baa35ad99f26f1b399c31f3c666a7fc67ecef3bdcdb7d60e8ada90b722 str_sha224 : 173994f309f727ca939bb185086cd7b36e66141c9e52ba0bdcfd145d 
      str_sha384 : d1e67b8819b009ec7929933b6fc1928dd64b5df31bcde6381b9d3f90488d253240490460c0a5a1a873da8236c12ef9b3 
      str_sha256 : f6071725e7ddeb434fb6b32b8ec4a2b14dd7db0d785347b2fb48f9975126178f

crc32_encoding

Use the crc32_encoding function to calculate the cyclic redundancy check code of the data.

  • Function format
    crc32_encoding(data, input_format="raw", input_encoding="utf-8")
  • Parameter description

    Parameter

    Type

    Mandatory

    Description

    data

    String

    Yes

    Data to compute cyclic redundancy check code for.

    input_format

    String

    No

    Input format. The default value is raw. Options:

    • raw: bytes format
    • hex: hexadecimal format
    • base64: Base64 encoding format

    input_encoding

    String

    No

    Character encoding format. This parameter is mandatory only when input_format is set to raw. The default value is utf-8.

  • Returned result

    Cyclic redundancy check code of the input data.

  • Function example
    1. Example 1: Calculate the cyclic redundancy check code of the test field.
      • Test data
        {
          "test": "aatest"
        }
      • Processing rule
        e_set("str_crc32", crc32_encoding(v("test")))
      • Processing result
        str_crc32:1434103726
        test:aatest
    2. Example 2: Connect the fields test1 and test2, performs MD5 encoding, and calculates the cyclic redundancy check code.
      • Test data
        {
        "test1": "test1",
        "test2": "test2"
        }
      • Processing rule
        e_set(
            "str_crc32",
            crc32_encoding(
                md5_encoding(str_join("+", v("test1"), v("test2")), format="binary") 
           ),
        )
      • Processing result
        str_crc32:369733261 
        test1:test1 
        test2:test2
    3. Example 3: Calculates the cyclic redundancy check code of the field test. The value is in Base64 encoding format.
      • Test data
        {
         "test": "Taloz+e+PzP3NltrEXiCig=="
        }
      • Processing rule
        e_set("str_crc32", crc32_encoding(v("test"), input_format="base64"))
      • Processing result
        str_crc32:1093789404
        test:Taloz+e+PzP3NltrEXiCig==