Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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 '$$'

question from:https://stackoverflow.com/questions/65952527/is-it-posible-in-dataweaver-1-0-decapitalise-first-letter-in-key-name-not-value

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
890 views
Welcome To Ask or Share your Answers For Others

1 Answer

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"
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...