Mule Dataweave - 如何将数组转换成对象数组。

问题描述 投票:0回答:1

如果有人能帮助下面的数据编织表达式,将会很有帮助。

  [
    [
       {"attribute": "a", "value": "2193605"}, 
       {"attribute": "b", "value": "2020-01-01"},
       {"attribute": "c", "value": "3000"}
    ], 
    [
       {"attribute": "a", "value": "3373448"},
       {"attribute": "b", "value": "2020-01-01"}, 
       {"attribute": "b", "value": "800"}
    ]
  ]

变成

[
    {"a": "2193605", "b": "2020-01-01", "c": "3000"},
    {"a": "3373448", "b": "2020-01-01", "c": "800"}
]
dataweave mulesoft mule-esb
1个回答
2
投票
%dw 2.0
output application/json
---
payload map((item) ->
    item reduce((e,accum={}) ->
        accum ++ (e.attribute): e.value
    )
)
© www.soinside.com 2019 - 2024. All rights reserved.