是否有可能在 dataweave 1.0 中大写键名中的第一个字母,而不是值?

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

我有这样的输入:

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

我想在转换后得到这样的输出:

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

我该怎么做? 试过这样:

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

但出现错误:

There is no variable named '$$'

您必须使用 mapObject 来更改键。请注意 $$ 仅在某些运算符的上下文中才有意义。您需要将整个键表达式放在括号之间。我改用了模式匹配。

示例:

%dw 1.0
%output application/java
%function lowerFirst(s)
    s[0] match {
        'A' -> 'a' ++ s[1..-1],
        'B' -> 'b' ++ s[1..-1],
        // add other letters mapping       
        default -> s
    }
     
---
payload mapObject (lowerFirst($$)): $

注意需要在函数中完成字母映射

试试这个:

输入

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

脚本

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

输出

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