Search code examples
muledataweavemule-componentmule-esb

Is it posible in dataweaver 1.0 decapitalise first letter in key name, not value?


I have such input:

{
 Abc: "1",
 BcD: "2",
 ...
 klm: "3",
 ZXC: "4"
} 

I want to get output after transform like this:

{
 abc: "1",
 bcD: "2",
 ...
 klm: "3",
 zXC: "4"
} 

How I can do that? Have been tried like that:

%dw 1.0
%output application/json
---
{
  ($$) replace /^([A-Z])/ with lower $$[1] : $
}

but getting error:

There is no variable named '$$'


Solution

  • Try with this:

    Input

    {
     "Abc": "1",
     "BcD": "2",
     "klm": "3",
     "ZXC": "4"
    } 
    

    Script

    %dw 1.0
    %input payload application/json
    %output application/json
    ---
    payload mapObject {
      (lower ($$)[0] ++ (($$)[1 to -1])):$
    }
    

    Output

    {
      "abc": "1",
      "bcD": "2",
      "klm": "3",
      "zXC": "4"
    }