---
title: "base64encode Formula Function: Encode Text as Base64 in Nodinite Search Fields"
description: The base64encode Formula function encodes text from the message body, a context property, or another function as base64, with an optional input encoding such as UTF-8 or ISO-8859-1.
---

# <i class="fal fa-function" aria-hidden="true"></i> Formula - base64encode

The `base64encode` [Formula][] function returns the base64 representation of text, encoded to bytes with UTF-8 or with the input encoding you name.

![Encode the order id and the customer name of an Order-to-Cash event as base64 with base64encode, animated walkthrough (7.12)][hero]  
*Animated walkthrough: on the JSON Order Received event of order ORD-10005 in the [Order-to-Cash demo][], `base64encode(jsonPath('$.orderId', body))` returns `T1JELTEwMDA1`, the UTF-8 bytes of `ORD-10005`. With the input encoding `'iso-8859-1'`, the customer name `Tailspin Toys` becomes `VGFpbHNwaW4gVG95cw==`; plain ASCII text gives the same result in UTF-8.*  

## <i class="fal fa-code" aria-hidden="true"></i> Syntax

```text
base64encode(content [, 'input encoding'])
```

### Parameters

|Parameter|Required|Description|
|---|---|---|
|`content`|Yes|The text to encode: [body][], [context][], or the result of another function, such as [jsonPath][].|
|`'input encoding'`|No|The character encoding used to turn the text into bytes before base64 encoding, such as `'UTF-8'` or `'iso-8859-1'`. Without it, UTF-8 is used.|

### Returns

The base64 text. When the content holds several values, for example from `jsonPath`, each value is encoded and returned as its own [Search Field][] value. When the content has no value, nothing is returned.

## <i class="fal fa-list-ol" aria-hidden="true"></i> Examples

### Example 1: Encode the message body

#### Input

```text
Nodinite
```

#### Formula

```text
base64encode(body)
```

#### Result

```text
Tm9kaW5pdGU=
```

![Test Expression tab: base64encode(body) encodes the message body Nodinite to Tm9kaW5pdGU= (7.12)][1]  
*Plain ASCII text gives the same base64 result in UTF-8 and ISO-8859-1.*  

### Example 2: Encode text as ISO-8859-1

#### Input

```text
Skellefteå
```

#### Formula

```text
base64encode(body, 'iso-8859-1')
```

#### Result

```text
U2tlbGxlZnRl5Q==
```

![Test Expression tab: base64encode(body, 'iso-8859-1') encodes Skellefteå to U2tlbGxlZnRl5Q== (7.12)][2]  
*With ISO-8859-1, `å` is the single byte E5. With the default UTF-8, the result is `U2tlbGxlZnRlw6U=` instead.*  

### Example 3: Encode a context property

#### Input

|Key|Value|
|---|---|
|`id`|`Simple`|

#### Formula

```text
base64encode(context('id'))
```

#### Result

```text
U2ltcGxl
```

![Test Expression tab: base64encode(context('id')) encodes the context value Simple to U2ltcGxl (7.12)][3]  
*The value of the context property `id` is encoded; the message body isn't used.*  

### Example 4: Encode several values from a JSON body

#### Input

```json
[
    { "name": "Hello" },
    { "name": "World" }
]
```

#### Formula

```text
base64encode(jsonPath('$..name',body))
```

#### Result

```text
SGVsbG8=
V29ybGQ=
```

![Test Expression tab: base64encode of a jsonPath result returns SGVsbG8= and V29ybGQ= (7.12)][4]  
*`jsonPath` returns two values, and `base64encode` encodes each one: two unique matches.*  

## <i class="fal fa-circle-info" aria-hidden="true"></i> Notes

* Pick the input encoding the receiving system expects; to re-encode text without base64, use [convert][]. Characters outside ASCII, such as `å`, `ö`, and `é`, give different base64 results in UTF-8, ISO-8859-1, and Windows-1252.
* Encoding names follow .NET; see the [List of encodings](https://learn.microsoft.com/en-us/dotnet/api/system.text.encoding?view=net-6.0#list-of-encodings)<sup><i class="fal fa-arrow-up-right-from-square" aria-hidden="true"></i></sup>.

## <i class="fal fa-hand-point-right" aria-hidden="true"></i> Next Steps

* <i class="fal fa-magnifying-glass-plus" aria-hidden="true"></i> [Add or manage Search Field][]  
* <i class="fal fa-flask" aria-hidden="true"></i> [Test Your Expression][]  
* <i class="fal fa-hard-drive" aria-hidden="true"></i> [Add or manage Log View][]  

## <i class="fal fa-link-horizontal" aria-hidden="true"></i> Related Topics

* <i class="fal fa-unlock" aria-hidden="true"></i> [base64decode][]  
* <i class="fal fa-language" aria-hidden="true"></i> [convert][]  
* <i class="fal fa-arrow-down-a-z" aria-hidden="true"></i> [toLowerCase][]  
* <i class="fal fa-arrow-up-a-z" aria-hidden="true"></i> [toUpperCase][]  
* <i class="fal fa-function" aria-hidden="true"></i> [Formula][]  
* <i class="fal fa-scroll" aria-hidden="true"></i> [Formula language rules][]  
* <i class="fal fa-puzzle-piece" aria-hidden="true"></i> [Search Field Expressions][]  
* <i class="fal fa-language" aria-hidden="true"></i> [Character Encoding][]  

[1]:https://docs.nodinite.com/media/Documentation%20Pictures/IM/WebClient/Admin/Log/Search%20Fields/Plugins/Formula/Convert/base64encode-message-body.png
[2]:https://docs.nodinite.com/media/Documentation%20Pictures/IM/WebClient/Admin/Log/Search%20Fields/Plugins/Formula/Convert/base64encode-message-body-withencoding.png
[3]:https://docs.nodinite.com/media/Documentation%20Pictures/IM/WebClient/Admin/Log/Search%20Fields/Plugins/Formula/Convert/base64encode-messageContext.png
[4]:https://docs.nodinite.com/media/Documentation%20Pictures/IM/WebClient/Admin/Log/Search%20Fields/Plugins/Formula/Convert/base64encode_functionAsContent.png

[Add or manage Log View]:https://docs.nodinite.com/administration/log-management/log-views/features/add-or-manage-log-view/
[Add or manage Search Field]:https://docs.nodinite.com/administration/log-management/search-fields/features/add-or-manage-search-field/
[base64decode]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/convert/base64decode/
[body]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/source/body/
[Character Encoding]:https://docs.nodinite.com/core-services/log-event/features/character-encoding/
[Context]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/source/context/
[convert]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/convert/convert/
[Formula]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/overview/
[Formula language rules]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/overview/#fa-scroll-formula-language-rules
[hero]:https://docs.nodinite.com/media/Documentation%20Pictures/IM/WebClient/Admin/Log/Search%20Fields/Plugins/Formula/Convert/Formula_Base64Encode.gif
[jsonPath]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/extract/jsonpath/
[Order-to-Cash demo]:https://docs.nodinite.com/repository-model/bpms/examples/order-to-cash/generate-o2c-demo-data/
[Search Field]:https://docs.nodinite.com/administration/log-management/search-fields/features/what-is-a-search-field/
[Search Field Expressions]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/overview/
[Test Your Expression]:https://docs.nodinite.com/administration/log-management/search-fields/features/add-or-manage-search-field/#test-your-expression
[toLowerCase]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/convert/tolowercase/
[toUpperCase]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/convert/touppercase/