[英]mapping payload with json object in dataweave
What I'm trying to do is map the CodeOT to each object in my payload such as :我想要做的是将 CodeOT 映射到我的有效负载中的每个对象,例如:
null/0 get the value 1 1 to 5 get the value 2 and 6 to 9 get the value 3 null/0 获取值 1 1 到 5 获取值 2 和 6 到 9 获取值 3
I am lost in how to do it as I'm new to dataweave我不知道该怎么做,因为我是 dataweave 的新手
example of payload :有效载荷示例:
{
"refSig" : "0110443372",
"indSap":2
},
{
"refSig" : "0000443942",
"indSap":0
},
{
"refSig" : "0117243942",
"indSap":null
}
the conversion table is provided and must be used as is, here's a part of it提供了转换表,必须按原样使用,这是其中的一部分
{
"CodeSap": null,
"Libelle": "",
"CodeOT": 1
},
{
"CodeSap": 0,
"Libelle": "Elle a demandé un délai de paiement",
"CodeOT": 1
},
{
"CodeSap": 1,
"Libelle": "Elle a des factures SATD",
"CodeOT": 2
},
{
"CodeSap": 2,
"Libelle": "Elle a des factures remises à l’huissier",
"CodeOT": 2
}
I need to map the CodeOT from the conversion table to the indSap from the payload using CodeSap我需要使用 CodeSap 将转换表中的 CodeOT 映射到有效负载中的 indSap
I started doing this but it doesn't seem to lead me anywhere我开始这样做,但它似乎并没有把我带到任何地方
%dw 2.0
output application/json
---
lignesOK : payload map (item, index) -> {
bf: item mapObject (value, key) -> {
(key): value,
codeOt: varTable map (it,val) ->{
(val):(it)
}
}
}
expected output for the example of the payload above is :上述有效负载示例的预期输出为:
{
"refSig" : "0110443372",
"CodeOT":2
},
{
"refSig" : "0000443942",
"CodeOT":1
},
{
"refSig" : "0117243942",
"CodeOT":1
}
Assuming that the input and table are arrays and that entries in the table are unique per CodeSap
the following script works, though the output is a bit different than expected because of the incomplete table provided:假设输入和表是数组,并且表中的条目对于每个
CodeSap
都是唯一的,则以下脚本可以工作,尽管由于提供的表不完整,输出与预期有些不同:
%dw 2.0
output application/json
var varTable=[{
"CodeSap": null,
"Libelle": "",
"CodeOT": 1
},
{
"CodeSap": 0,
"Libelle": "Elle a demandé un délai de paiement",
"CodeOT": 1
},
{
"CodeSap": 1,
"Libelle": "Elle a des factures SATD",
"CodeOT": 2
},
{
"CodeSap": 2,
"Libelle": "Elle a des factures remises à l’huissier",
"CodeOT": 2
}]
---
payload map (item, index) -> {
refSig: item.refSig,
codeOt: (varTable filter (item.indSap == $.CodeSap))[0].CodeOT
}
Output:输出:
[
{
"refSig": "0110443372",
"codeOt": null
},
{
"refSig": "0000443942",
"codeOt": 1
},
{
"refSig": "0117243942",
"codeOt": 1
}
]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.