Mule 4 DataWeave 2 数组映射
Mule 4 DataWeave 2 Mapping of Arrays
任何人都可以帮助这个数据编织吗?我正在尝试将这个位于“块”中的输入映射为拆分成单个元素。我有以下有效载荷
[{
"invoiceId": [
9808,
9797
],
"items": [{
"order_item_id": [
25630,
25805]},
{
"qty": [
"1",
"1"
]
},
{
"extension_attributes": {
"credit_reason": [
"Cancelled",
"Unwanted Return"
]
}
}
],
"isOnline": true,
"notify": true,
"appendComment": true,
"comment": {
"comment": "<b>Reason:</b> Bulk Refund </br>"
},
"arguments": {
"shipping_amount": [
0,
0
],
"extension_attributes": {
"rd_creditmemo_payment_credited": 1,
"rd_send_email": 1
}
}
}
]
我正在尝试获取下面的输出,其中的块被分成单独的条目
[
{
"invoiceId": 9808,
"items": [
{
"order_item_id": 25630,
"qty": "1",
"extension_attributes": {
"credit_reason": "Cancelled"
}
}
],
"isOnline": false,
"notify": false,
"appendComment": true,
"comment": {
"comment": "<b>Reason:</b>Bulk Refunded</br>"
},
"arguments": {
"shipping_amount": 0,
"extension_attributes": {
"rd_credittmemo_payment_credited": 1,
"rd_send_email": 1
}
}
},
{
"invoiceId": 9797,
"items": [
{
"order_item_id": 25805,
"qty": "1",
"extension_attributes": {
"credit_reason": "Unwanted Return"
}
}
],
"isOnline": false,
"notify": false,
"appendComment": true,
"comment": {
"comment": "<b>Reason:</b>Bulk Refunded</br>"
},
"arguments": {
"shipping_amount": 4.95,
"extension_attributes": {
"rd_credittmemo_payment_credited": 1,
"rd_send_email": 1
}
}
}
]
非常感谢任何帮助。提前致谢!
这是实现此目的的方法。
%dw 2.0
output application/json
---
payload[0].invoiceId map ((invoiceId, index) -> {
invoiceId: invoiceId,
items: [
do {
var itemObj = payload[0].items
---
{
order_item_id: flatten(itemObj..order_item_id)[index],
qty: flatten(itemObj..qty)[index],
extension_attributes: {
credit_reason: flatten(itemObj..extension_attributes.credit_reason)[index]
}
}
}],
arguments: do {
var arg = payload[0].arguments
---
{
shipping_amount: arg.shipping_amount[index],
} ++ arg - "shipping_amount"
}
} ++ payload[0] - "invoiceId" - "items" - "arguments")
任何人都可以帮助这个数据编织吗?我正在尝试将这个位于“块”中的输入映射为拆分成单个元素。我有以下有效载荷
[{
"invoiceId": [
9808,
9797
],
"items": [{
"order_item_id": [
25630,
25805]},
{
"qty": [
"1",
"1"
]
},
{
"extension_attributes": {
"credit_reason": [
"Cancelled",
"Unwanted Return"
]
}
}
],
"isOnline": true,
"notify": true,
"appendComment": true,
"comment": {
"comment": "<b>Reason:</b> Bulk Refund </br>"
},
"arguments": {
"shipping_amount": [
0,
0
],
"extension_attributes": {
"rd_creditmemo_payment_credited": 1,
"rd_send_email": 1
}
}
}
]
我正在尝试获取下面的输出,其中的块被分成单独的条目
[
{
"invoiceId": 9808,
"items": [
{
"order_item_id": 25630,
"qty": "1",
"extension_attributes": {
"credit_reason": "Cancelled"
}
}
],
"isOnline": false,
"notify": false,
"appendComment": true,
"comment": {
"comment": "<b>Reason:</b>Bulk Refunded</br>"
},
"arguments": {
"shipping_amount": 0,
"extension_attributes": {
"rd_credittmemo_payment_credited": 1,
"rd_send_email": 1
}
}
},
{
"invoiceId": 9797,
"items": [
{
"order_item_id": 25805,
"qty": "1",
"extension_attributes": {
"credit_reason": "Unwanted Return"
}
}
],
"isOnline": false,
"notify": false,
"appendComment": true,
"comment": {
"comment": "<b>Reason:</b>Bulk Refunded</br>"
},
"arguments": {
"shipping_amount": 4.95,
"extension_attributes": {
"rd_credittmemo_payment_credited": 1,
"rd_send_email": 1
}
}
}
]
非常感谢任何帮助。提前致谢!
这是实现此目的的方法。
%dw 2.0
output application/json
---
payload[0].invoiceId map ((invoiceId, index) -> {
invoiceId: invoiceId,
items: [
do {
var itemObj = payload[0].items
---
{
order_item_id: flatten(itemObj..order_item_id)[index],
qty: flatten(itemObj..qty)[index],
extension_attributes: {
credit_reason: flatten(itemObj..extension_attributes.credit_reason)[index]
}
}
}],
arguments: do {
var arg = payload[0].arguments
---
{
shipping_amount: arg.shipping_amount[index],
} ++ arg - "shipping_amount"
}
} ++ payload[0] - "invoiceId" - "items" - "arguments")