Dataweave 代码不工作在 mule3 中工作的 mule 4

Dataweave code not working mule 4 which was working in mule3

以下代码片段在 3.8 中有效但在 4.1 中无效:

output application/java
var csv = payload
---
(csv map $ reduce ((val,acc) -> ((acc) ++ ((val)) ))) map ($ replace ',' with '\t')

input payload: 

{"D01":{"AK":"D,01,AK,0,0,0,0,0,-2.89,0.00,0,0,0,0,0",
        "AL":"D,01,AL,829.23,18506.35,0,0.00,0,-6610.91,0.00,0,0,0,159.66,-1.94"},
"D02.1":{"AK":"D,02.1,AK,0,0,0,0,0,-6.76,0.00,0,0,0,0,0",
        "AL":"D,02.1,AL,7733.77,304148.90,0,0.00,0,-42791.15,0.00,0,0,0,1347.09,-8.88"}
} 

在此处输入代码

预期输出: [ "D\t01\tAK\t0\t0\t0\t0\t0\t-2.89\t0.00\t0\t0\t0\t0\t0", "D\t01\tAL\t829.23\t18506.35\t0\t0.00\t0\t-6610.91\t0.00\t0\t0\t0\t159.66\t-1.94", "D\t02.1\tAK\t0\t0\t0\t0\t0\t-6.76\t0.00\t0\t0\t0\t0\t0", "D\t02.1\tAL\t7733.77\t304148.90\t0\t0.00\t0\t-42791.15\t0.00\t0\t0\t0\t1347.09\t-8.88" ]

低于错误:

org.mule.runtime.core.internal.exception.OnErrorPropagateHandler:


消息:“您使用这些参数调用了函数 'map':
1:字符串("{\"D01\":{\"AK\":\"D,01,AK,0,0,0,0,0,-2.89,0.00,0,0,0,0,0\",\"AL\":\"D,01,A...)
2: 函数 (($:Any, $$:Any) -> ???)

但它需要这些类型的参数:
1: 数组
2: 函数

13| (csv ma​​p $ reduce ((val,acc) -> ((acc) ++ ((val)) ))) map ($replace ',' with '\t') ^^^^^^^^^

我认为问题在于,DataWeave 2 中的 mapObject 上不起作用(参见 changes)。 DataWeave 1 允许这样做,因此您的代码对 DataWeave 1 有效。

根据 DataWeave 1 的输出,我认为您可以对 DataWeave 2 使用以下代码 -

%dw 2.0
output application/java
var csv = payload
---
flatten ((csv pluck $) map ($ pluck $)) map ($ replace ',' with '\t')

pluck 会将对象拆分为两个数组 - 值 ($) 和键 ($$)。