繁体   English   中英

使用Dataweave修改现有的有效负载数组

[英]Modify existing payload array using Dataweave

请查看传入的m子有效载荷:(我在ule子3.9上)

 {
        "source": {
            "code": "CD-12"
        },
        "target": {
            "code": "CD-22"
        },
        "entities": [
            {
                "ID": "ABC",
                "sourceEnt": {
                    "entityId": "100A",
                    "entityName": "ID-1"
                },
                "targetEnt": {
                    "Account": {
                        "Key1": "Value1",
                        "Key2": "Value2"
                    },
                    "Address": [
                        {
                            "Name21": "Value21"
                        }
                    ],
                    "AccountAddress": [
                        {
                            "Key31": "Value31",
                            "Key32": "Key32"
                        }
                    ]
                }
            }
        ]
    }

我是Mule dataweave的新手。 如何修改特定实体下的特定数组。 例如,如果我需要在targetEnt帐户下添加“ Key3”和“ Value3”? 我在下面粘贴示例代码。

%dw 1.0
%output application/json
---
{

    entities : payload.entities map 
    {
        ID: ID
        entity : $.targetEnt
    } //++ {"Key3":"Value3"} when $.targetEnt: "Account"
}

我认为您需要做的是

%dw 1.0
%output application/json
---
{

    entities : payload.entities map ((item, index) ->
    {
        ID: item.ID,
        entity : item.targetEnt mapObject ((value, key) -> { 
          (key): value ++ {"Key3":"Value3"} when  key ~= "Account" otherwise value

        })
    }) 
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM