encode()
Encodes a string to a binary object based on the specified encoding.
Syntax
encode(STR, [CHARSET])
Required Parameter
STR
- Expression that returns a string. The function returns
null
if a non-string value is received.
Optional Parameter
CHARSET
- Character set (default: utf-8). Use the preferred MIME name or aliases registered in the IANA Charset. https://www.iana.org/assignments/character-sets/character-sets.xhtml
Usage
json "{}"
| eval encoded=encode("hello, world!"), decoded=decode(encoded)
=> encoded: 68656c6c6f2c20776f726c6421 # Binary
=> decoded: "hello, world!" # String