withMaxSize(String, Number): String

Checks that the string length is no larger than the specified maxLength. If the string’s length is larger than the maxLength, the function cuts characters from left to right, until the string length meets the length limit.

Introduced in DataWeave 2.3.0. Supported by Mule 4.3 and later.


Name Description


The input string.


The maximum length of the string.


This example shows how withMaxSize behaves with different inputs and sizes. Note that if withMaxSize is 0, the function returns an empty string. If the input is null, the output is always null.


%dw 2.0
import withMaxSize from dw::core::Strings
output application/json
   a: "123" withMaxSize 10,
   b: "123" withMaxSize 3,
   c: "123" withMaxSize 2,
   d: "" withMaxSize 0,
   e: null withMaxSize 23,


  "a": "123",
  "b": "123",
  "c": "12",
  "d": "",
  "e": null

withMaxSize(Null, Number): Null

Helper function that enables withMaxSize to work with a null value.

Was this article helpful?

💙 Thanks for your feedback!

Edit on GitHub
Submit your feedback!
Share your thoughts to help us build the best documentation experience for you!
Take our latest survey!