I have this JSON
output of a SAP
function:
{
"Z_HYD_GET_INVOICES": {
"import": {
"BRANCH": "0142",
"DOCNUMS": null,
"FINAL_DATE": "Tue Oct 08 00:00:00 BST 2019",
"INITIAL_DATE": "Mon Oct 07 00:00:00 BST 2019"
},
"export": {
"ACCOUNTING": {
"row": {
"DOCNUM": "0002990790",
"PSTDAT": "Mon Oct 07 00:00:00 BST 2019",
"BUKRS": "TRV"
},
"row": {
"DOCNUM": "0003006170",
"PSTDAT": "Mon Oct 07 00:00:00 BST 2019",
"BUKRS": "TRV"
}
},
"FISCAL": {
"row": {
"DOC_DOCNUM": "0002990790",
"DOC_NFTYPE": "ZW"
},
"row": {
"DOC_DOCNUM": "0003006170",
"DOC_INVTYPE": "ZW"
}
},
"MESSAGE_RETURN": null,
"STATUS_RETURN": null
}
}
}
And I want it to be like this:
{
"invoices": [
{
"accounting":
{
"accountingDocumentID": "0002990790",
"taxEntryDate": "Mon Oct 07 00:00:00 BST 2019",
"company": "TRV"
},
"fiscal":
{
"fiscalDocument": {
"fiscalDocumentID": "0002990790",
"fiscalDocumentCategory": "ZW"
}
}
},
{
"accounting":
{
"accountingDocumentID": "0003006170",
"taxEntryDate": "Mon Oct 07 00:00:00 BST 2019",
"company": "TRV"
},
"fiscal":
{
"fiscalDocument": {
"fiscalDocumentID": "0003006170",
"fiscalDocumentCategory": "ZW"
}
}
}
]
}
I already tried some code with map
and mapObject
, but neither worked.
FISCAL.DOC_DOCNUM
is equal to FISCAL.DOCNUM
, but it could be better to if the transformation fits by position. I mean, join the first element of ACCOUNTING with the first one of FISCAL, and so on... If someone could also provide transform joining by ID, it'll be really nice, for future reference.