---
title: Formula length – Character Count of Values in Nodinite Search Field Expressions
description: The length function in the Nodinite Formula plugin returns the character count of each value in the content. Syntax, the unique parameter, and tested examples for message body, message context, xPath, and jsonPath.
---

# :fa-function: Formula - Length

The `length` function, one of the Math functions in the [Formula][] plugin for [Search Field Expressions][], returns the character count of each value in the content.

![Measure the customer name in the body and the order number in the message context of an Order-to-Cash event with length, animated walkthrough (7.12)][hero]  
*Animated walkthrough: on the JSON Order Received event of order ORD-10005 in the [Order-to-Cash demo][], `length(jsonPath('$.customer.name', body))` returns `13` for `Tailspin Toys`, the space included. On the Message Context tab, `length(context('OrderNumber'))` returns `9` for `ORD-10005`.*  

## :fa-code: Syntax

```text
length(content [, unique])
```

### Parameters

| Parameter | Required | Description |
| --- | --- | --- |
| `content` | ✅ Yes | The values to measure: [body][], [context][Context], or another Formula function such as [xPath][] or [jsonPath][]. |
| `unique` | ❌ No | Unquoted `true` or `false`; default `true` for this function. `false`: a value that appears several times counts every time. `true`: identical values count once. Values are compared as text, so `100` and `100.00` are different values. A quoted `'true'` is an error. |

### Returns

* One character count per value in `content`; several input values give several counts (see [Example 4](#example-4-measure-each-value-extracted-from-json)).
* To get a single number from several counts, wrap `length` in [max][], [min][], [sum][], or [avg][average] (see [max][]).

Quoting, nesting, and how `content` is resolved are described in the [Formula language rules][].

## :fa-list-ol: Examples

### Example 1: Measure a city name in an XML order

#### Input

Message Body:

```xml
<ns0:Orders xmlns:ns0="SupplyChain.Schemas/1.0">
  <Order>
    <Id>1337</Id>
    <Amount>666</Amount>
    <City>New York</City>
    <Partner>QWNtZQ==</Partner>
  </Order>
</ns0:Orders>
```

#### Formula

```text
length(xPath('Orders/Order/City', body))
```

#### Result

```text
8
```

`New York` is eight characters long, including the space.

![Test Expression tab: length(xPath('Orders/Order/City', body)) on an order with City New York returns 8 (7.12)][ex1]  
*`length` measures the extracted text, not the XML element, so the tags don't count.*  

### Example 2: Measure the message body

#### Input

Message Body:

```text
Nodinite
```

#### Formula

```text
length(body)
```

#### Result

```text
8
```

![Test Expression tab: length(body) on the message body Nodinite returns 8 (7.12)][1]  
*`Nodinite` has eight characters, so `length` returns `8`.*  

### Example 3: Measure a message context value

#### Input

Message Context:

| Key | Value |
| --- | --- |
| `Correlation Id` | `demo001` |
| `Header#Content-Type` | `Application/XML` |

#### Formula

```text
length(context('Correlation Id'))
```

#### Result

```text
7
```

![Test Expression tab: length(context('Correlation Id')) on the context value demo001 returns 7 (7.12)][2]  
*Only the `Correlation Id` key is read; its value `demo001` has seven characters.*  

### Example 4: Measure each value extracted from JSON

#### Input

Message Body:

```text
{a:[{b:'This'},{b:'is'},{b:'Formula Plugin'}]}
```

#### Formula

```text
length(jsonPath('a[*].b', body), true)
```

#### Result

```text
4
2
14
```

![Test Expression tab: length of the jsonPath values of every b in the array a, with unique true, returns 4, 2, and 14 (7.12)][3]  
*[jsonPath][] extracts three values, and `length` returns one count for each: `This` (4), `is` (2), and `Formula Plugin` (14).*  

## :fa-hand-point-right: Next Steps

* :fa-magnifying-glass-plus: [Add or manage Search Field][]  
* :fa-flask: [Test Your Expression][]  
* :fa-hard-drive: [Add or manage Log View][]  

## :fa-link-horizontal: Related Topics

* :fa-calculator: [avg][average]  
* :fa-hashtag: [count][]  
* :fa-arrow-up-wide-short: [max][]  
* :fa-arrow-down-short-wide: [min][]  
* :fa-circle-half-stroke: [round][]  
* :fa-plus: [sum][]  
* :fa-function: [Formula][]  
* :fa-scroll: [Formula language rules][]  
* :fa-puzzle-piece: [Search Field Expressions][]  

[1]:{ndm}/Documentation%20Pictures/IM/WebClient/Admin/Log/Search%20Fields/Plugins/Formula/Math/LengthFromBodyString.png
[2]:{ndm}/Documentation%20Pictures/IM/WebClient/Admin/Log/Search%20Fields/Plugins/Formula/Math/LengthContext.png
[3]:{ndm}/Documentation%20Pictures/IM/WebClient/Admin/Log/Search%20Fields/Plugins/Formula/Math/LengthJsonpath.png

[Add or manage Log View]:{ndr}/Administration/1.%20Log%20Management/1.%20Log%20Views/Features/Add%20or%20Manage%20Log%20View.md
[Add or manage Search Field]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Add%20or%20manage%20Search%20Field.md
[average]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Formula/Math/average.md
[body]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Formula/Source/body.md
[Context]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Formula/Source/context.md
[count]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Formula/Math/count.md
[ex1]:{ndm}/Documentation%20Pictures/IM/WebClient/Admin/Log/Search%20Fields/Plugins/Formula/Math/length_Example1.png
[Formula]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Formula/Overview.md
[Formula language rules]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Formula/Overview.md#fa-scroll-formula-language-rules
[hero]:{ndm}/Documentation%20Pictures/IM/WebClient/Admin/Log/Search%20Fields/Plugins/Formula/Math/Formula_Length.gif
[jsonPath]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Formula/Extract/jsonPath.md
[max]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Formula/Math/max.md
[min]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Formula/Math/min.md
[Order-to-Cash demo]:{ndr}/Repository%20Model/BPMs/Examples/Order-to-Cash/Generate-O2C-Demo-Data.md
[round]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Formula/Math/round.md
[Search Field Expressions]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Overview.md
[sum]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Formula/Math/sum.md
[Test Your Expression]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Add%20or%20manage%20Search%20Field.md#test-your-expression
[xPath]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Formula/Extract/xPath.md