json - 使用 Dataweave 修改现有的有效负载数组
问题描述
请查看我传入的 mule 有效负载:(我在 Mule 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 Account下添加“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
})
})
}
推荐阅读
- mysql - 为什么我的查询在尝试创建表时返回 SQL 语法错误 - MariaDB?
- excel - VBA - 使用 WorksheetFunction.SumIFs 的运行时错误 13 类型不匹配
- html - Unity Webgl 游戏以网页为中心
- python - python代码中的一些奇怪的东西,map()函数
- python - Python代码未打印所需的结果
- r - 将两侧倾斜的数据转换为 R 中的正态分布
- oracle-apex - 单击特定条形时如何从 oracle apex 上的条形图中获取值?
- javascript - 如何使用 Puppeteer 节点 js 获取 querySelectorAll 的第二个元素并循环遍历其元素
- javascript - JS文件中的输出条件
- html - 页面没有在反应 js 中包装整个网页内容