--- type: "fhirpath-function" title: "FHIRPath Function: encode" function: "encode" category: "Additional String Functions" section: "5.7.1" source: "fhirpath/functions.json" --- # FHIRPath Function: encode {:.stu} The encode function takes a singleton string and returns the result of encoding that string in the given format. The format parameter defines the encoding format. Available formats are: {:.stu} |hex |The string is encoded using hexadecimal characters (base 16) in lowercase | |=|=| |base64 |The string is encoded using standard base64 encoding, using A-Z, a-z, 0-9, +, and /, output padded with = | |urlbase64 |The string is encoded using url base 64 encoding, using A-Z, a-z, 0-9, -, and _, output padded with = | |ascii | The string has any character above character code 127 replaced with `?`. *This is a lossy encoding, and not reversible via `decode`* {:.grid} {:.stu} Base64 encodings are described in [RFC4648](https://tools.ietf.org/html/rfc4648#section-4). {:.stu} If the input is empty, the result is empty. {:.stu} If no format is specified, the result is empty. {:.stu} ## Summary - **Category**: Additional String Functions - **Section**: `5.7.1` - **Return Type**: `String` - **Empty Input Result**: `empty` - **Errors on Multiple Input**: `true` ## Description The encode function takes a singleton string and returns the result of encoding that string in the given format. Available formats are hex, base64, and urlbase64. ## Arguments - `format`: `String` - Encoding format (hex, base64, urlbase64) ## Type Mapping - `String-String` ## Example ```fhirpath 'test'.encode('hex') // returns hexadecimal representation ```