Hello friends, In this article we will see some common dataweave String functions from String core package(dw::core::Strings) along with their use-cases.
To use these functions in dataweave scripts we need to add/import the module header as below.
you can either import complete package by using * or if you want to use specific function you can use just function name in place of placeholder as given below <functionName>
%dw 2.0
import * from dw::core::Strings or import <functionName> from dw::core::Strings
output application/json
—
{}
Here, we will see 4 common String functions and their usage.
capitalize(String): String
camelize(String): String
dasherize(String): String
underscore(String): String
capitalize(String): String
This function accepts input as String and returns results as String. It capitalizes the first letter of each word in a string. It also removes underscores between words and puts a space before each capitalized word.
%dw2.0
import capitalize fromdw::core::Strings
output application/json
—
{
“a”: capitalize(“manish”),
“b”: capitalize(“mr_manish_kumar”),
“c”: capitalize(“manish-KUMAR”),
“d”: capitalize(“manishKumar”)
}
Output:
{
“a”: “Manish”,
“b”: “Mr Manish Kumar”,
“c”: “Manish Kumar”,
“d”: “Manish Kumar”
}
camelize(String): String
This function accepts input as String and returns results as String. It returns a string in camel case based on underscores in the string. All underscores are deleted, including any underscores at the beginning of the string.
%dw2.0
import camelize fromdw::core::Strings
output application/json
—
{
“a”: camelize(“1_manish”),
“b”: camelize(“mr_manish_kumar”),
“c”: camelize(“_manish_kumar”)
}
Output:
{
“a”: “1Manish”,
“b”: “mrManishKumar”,
“c”: “manishKumar”
}
dasherize(String): String
Thisfunction accepts input as String and returns results as String. It replaces spaces, underscores, and camel-casing in a string with dashes (hyphens). If no spaces, underscores, and camel-casing are present, the output will match the input.
Above function works based String input containing underscore. Below underscore function will help you to revert String to underscore format.
underscore(String): String
This function accepts input as String and returns results as String. It replaces hyphens, spaces, and camel-casing in a string with underscores. If no hyphens, spaces, and camel-casing are present, the output will match the input. Also it converts string into lower case.
I am having around 10 years of IT experience in Integration Architecture, Requirement gathering, Effort
Estimation, Application Design\Development\Testing and Deployment including 5+ years of experience in MuleSoft ESB and Hybrid Integrations.
DevOps and Cloud Integration is my area of interest.
It’s awesome to go to see this website and reading the views of alll mates
regarding this post, while I am also keen of getting familiarity.