如何使用dataweave将数组的对象转置对象

发布于 2025-01-24 21:19:24 字数 338 浏览 3 评论 0原文

如何在dataWeave中转置数组对象以获取一个JSON对象? 例如,我想

{
  "date": "20201124",
  "number": "NF006002CC21140000"
}

从下面的输入中获得像输出

[
  {
    "name": "date",
    "value": "20201124",
    "type": "STRING"
  },
  {
    "name": "number",
    "value": "NF006002CC21140000",
    "type": "STRING"
  }
]

How to transpose object of array in DataWeave to get a single JSON Object?
For example , I want to get output like

{
  "date": "20201124",
  "number": "NF006002CC21140000"
}

from below input

[
  {
    "name": "date",
    "value": "20201124",
    "type": "STRING"
  },
  {
    "name": "number",
    "value": "NF006002CC21140000",
    "type": "STRING"
  }
]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你又不是我 2025-01-31 21:19:24

您可以通过将累加器定义为object的 Repard 操作

payload reduce ((item, accumulator={}) -> 
    {
        (accumulator),
        (item.name): item.value
    }
)

。代码>(item.name):item.Value 。

You can use reduce operation for this by defining the accumulator as an Object

payload reduce ((item, accumulator={}) -> 
    {
        (accumulator),
        (item.name): item.value
    }
)

Here as the keys of the JSON is dynamically generated, you have to wrap the key expression in parentheses like (item.name): item.value.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文