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

Categories

0 votes
943 views
in Technique[技术] by (71.8m points)

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

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

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

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...