I'm using Anypoint Studio 7.3 and Mule 4.2.
I'm transforming a payload but I'm getting a random null at the end of the new array and cannot work out why it is appearing when I process this record.
Can anyone see why this problem is occurring?
Dataweave Code
%dw 2.0
output application/json
---
payload.records flatMap
((record, index) ->
records.customers flatMap ((customer, index) ->
customers.transactions flatMap ((transaction, index) ->
transaction.prices filter (!isEmpty($)) map ((price, index) ->
{
recordId: record.recordId,
customerId: customer.customerId,
transactionId: transaction.sessionId,
name: customer.name,
value: price.value
})
)
)
)
Input JSON
{
"records": [
{
"recordId": "f4f80bc7",
"customers": [
{
"customerId": "a1f773b8",
"name": "J Smith",
"transactions": [
{
"transactionId": "f610bac1"
"prices": [
{
"value": 580
},
{
"value": 8403,
},
{
"value": 8983
}
]
}
]
}
]
}
]
}
Output JSON with random null
[
{
"recordId": "f4f80bc7",
"customerId": "a1f773b8",
"transationId": "f610bac1",
"name": "J Smith",
"value": 580
},
{
"recordId": "f4f80bc7",
"customerId": "a1f773b8",
"transationId": "f610bac1",
"name": "J Smith",
"value": 8403
},
{
"recordId": "f4f80bc7",
"customerId": "a1f773b8",
"transationId": "f610bac1",
"name": "J Smith",
"value": 8983
},
null
]
Thanks for any help
You can skip null elements in your array with the writer property skipNullOn.
output application/json skipNullOn="arrays"
.
Just a comment here: With your DW script and input, I couldn't reproduce your output with the null element in Mule 4.2