Camel Case in Snaplogic

How can we convert the string in Camel Case in mapper ?

In the expression language from the May 2019 (4.17) release you can.

Hi cstwart,
I found this documentation but looks like its not incorporated in mapper as we get “method not found error”.

Hi cstwart,

In order to use the new features you should probably upgrade your snaplex to the newest version.


Hi cstwart,

You could also use the following expression: “test upper case”.replace(/\b\w/g, chr => chr.toUpperCase())

1 Like

Sure, but in your example that is not really camel case. it should result in a string that looks like this:

Also, the camelCase method will be able to convert all sorts of strings into camel case. not just ones seperated by spaces. for example:

“foo–bar”.camelCase() -> fooBar

“foo**bar”.camelCase() ->fooBar

so if the use case is for special characters as well as spaces, I’d use the camelCase method

Hi cjhoward18,

To achieve this you could extend your expression: “test camel-case+&^%$#@!*to=upper”.replace(/\b\w/g, chr => chr.toUpperCase()).replace(/[^a-zA-Z0-9]/g, “”)

1 Like

Even that expression and example results in a string/strings not quite in camel case. It should result in a string like this: “testCamelCaseToUpper” for your example. The first word of a camel case word should be ALL lower case letters.
So, simply uppercasing the first letter of the recognized word will not achieve correct camel case, and not preserve already existing camel Case words. For another case similar to your example “test cAMEL-CASE+&^%$#@!*TO=UPPER”.camelCase() the result should be:
“testCAmelCaseToUpper” however your expression would result in: “TestCAMELCASETOUPPER”, so I would really recommend using the camelCase method given in 4.17 since designing an expression to do this for all cases will not be trivial.

You can use Lodash REPL:
to see how camelCasing should behave.