first(text: String, amount: Number): String

Returns characters from the beginning of a string to the specified number of characters in the string, for example, the first two characters of a string.

If the number is equal to or greater than the number of characters in the string, the function returns the entire string.

Introduced in DataWeave version 2.4.0.


Name Description


The string to process.


The number of characters to return. Negative numbers and 0 return an empty string. Decimals are rounded down to the nearest whole number.


This example returns the first five characters from a string.


%dw 2.0
import first from dw::core::Strings
output application/json
"hello world!" first 5



first(text: Null, amount: Any): Null

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

Introduced in DataWeave version 2.4.0.

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!