I'm working on trying to get from the below source/target structures, using Dataweave 2.0. I've tried various ways using nested maps and reduce scripts but having some difficulty.
The pain point is the customFieldList, I want to simplify the overall structure by changing the root field to be scriptId (for simplicity right now).
Any advice/help would be very much appreciated.
Source structure
{
"line": [{
"lineNumber": 0,
"credit": 17.98,
"customFieldList": {
"customField": [{
"internalId": "5780",
"scriptId": "custcol_del_externalid",
"value": "0000000111111"
},
{
"internalId": "1446",
"scriptId": "custcol_4601_witaxapplies",
"value": false
},
{
"internalId": "1837",
"scriptId": "custcol_nsts_gaw_col_approver",
"value": {
"internalId": "29540",
"name": "Alan Mcgee",
"typeId": "-4"
}
},
{
"internalId": "2648",
"scriptId": "custcol_foreign_expense",
"value": false
}
]
}
},
{
"lineNumber": 1,
"debit": 17.98,
"customFieldList": {
"customField": [{
"internalId": "5780",
"scriptId": "custcol_del_externalid",
"value": "0000000111111"
},
{
"internalId": "1446",
"scriptId": "custcol_4601_witaxapplies",
"value": false
},
{
"internalId": "1837",
"scriptId": "custcol_nsts_gaw_col_approver",
"value": {
"internalId": "29540",
"name": "Joe Davis",
"typeId": "-4"
}
},
{
"internalId": "2648",
"scriptId": "custcol_foreign_expense",
"value": false
}
]
}
}
]
}
Target structure
{
"line": [{
"lineNumber": 0,
"credit": 17.98,
"custcol_del_externalid": {
"value": "0000000111111",
"internalId": "5780"
},
"custcol_4601_witaxapplies": {
"value": false,
"internalId": "1446"
},
"custcol_nsts_gaw_col_approver": {
"value": false,
"internalId1": "1837",
"internalId2": "29540",
"name": "Alan Mcgee",
"typeId": "-4"
},
"custcol_foreign_expense": {
"value": false,
"internalId": "2648"
}
},
{
"lineNumber": 1,
"debit": 17.98,
"custcol_del_externalid": {
"value": "0000000111111",
"internalId": "5780"
},
"custcol_4601_witaxapplies": {
"value": false,
"internalId": "1446"
},
"custcol_nsts_gaw_col_approver": {
"value": false,
"internalId1": "1837",
"internalId2": "29540",
"name": "Joe Davis",
"typeId": "-4"
},
"custcol_foreign_expense": {
"value": false,
"internalId": "2648"
}
}
]
}