dataWeave元素转换数组到字符串

发布于 2025-01-25 13:10:44 字数 380 浏览 5 评论 0原文

任何人都可以根据输入数据(数组对象的项目)提供以下输出结构的数据启发逻辑。

输入数据

{
    "Items": [{
        "name": "Document",
        "value": ["Representative", "Manager"]
    }, {
        "name": "Product",
        "value": ["Sales", "Price"]
    }]
}

输出数据:

^(+Document:"Representative" +Document:"Manager") ^(+Product:"Sales" +Product:"Price")

Can anyone kindly provide the DataWeave logic for the below output structure based on the input data(Items of the array object).

Input Data

{
    "Items": [{
        "name": "Document",
        "value": ["Representative", "Manager"]
    }, {
        "name": "Product",
        "value": ["Sales", "Price"]
    }]
}

Output data:

^(+Document:"Representative" +Document:"Manager") ^(+Product:"Sales" +Product:"Price")

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

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

发布评论

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

评论(1

入怼 2025-02-01 13:10:44

解决此问题的最佳方法是使用MAP功能和Joinby的组合

%dw 2.0
output text/plain
---
payload.Items 
    map ((item, index) -> "^(" ++ 
        (item.value 
            map ((value, index) -> '+$(item.name):"$(value)"') 
            joinBy  " ") 
        ++ ")"
    )
joinBy  " "

The best way to solve this is by using a combination of map function and joinBy

%dw 2.0
output text/plain
---
payload.Items 
    map ((item, index) -> "^(" ++ 
        (item.value 
            map ((value, index) -> '+$(item.name):"$(value)"') 
            joinBy  " ") 
        ++ ")"
    )
joinBy  " "
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文