I am trying to create a jolt transformation in NIFI , I have a JSON message with header, detail and line details as an array with line detail object.
Can we Transform Header/Detail JSON into Detail JSON One separate JSON for each Detail with New Tag having flattened array of Detail Attribute values of "TRADETYP" and "TRANSPORT_CODE"
"TRADETYP_CODE_ALL" : [ "GR-BARGE", "EXP-AR", "CR-LCL" ]
Sample JSON
{
"TRADE_HEADER": {
"IDOC": {
"EDI_DC40": {
"DOCNUM": "0000012890",
"TABNAME": "EDI_DC40",
"CREDT": "20220126",
"CRETM": "041400"
},
"TRADEDETAIL": {
"SEGMENT": "1",
"TRADE_NUM": "NA-152",
"PACKAGE_GUID": "ASDER3785$%SDF",
"TRADEDETAILLINE": [
{
"DOC_QTY": "19956.930",
"ACT_NOM_CONSUMED_QTY": "0.000",
"REM_MAX_QTY_TE": "0.000",
"XMDOCNR": "5025087976",
"DOCITM": "0000012001",
"COMMODITY": "RB",
"TRADING_COMPANY": "3862",
"PERIODICITY": "PRAGUE",
"POSTING_DATE": "20211117",
"MARKET": "CME",
"TRADETYP": "GR",
"MAX_DOC_QTY": "19956.930",
"TRANSPORT_CODE": "BARGE",
"DOCNR": "4700253115"
},
{
"DOC_QTY": "12256.230",
"ACT_NOM_CONSUMED_QTY": "0.000",
"REM_MAX_QTY_TE": "0.000",
"XMDOCNR": "5025092776",
"DOCITM": "0000014021",
"COMMODITY": "RB",
"TRADING_COMPANY": "3862",
"PERIODICITY": "PRAGUE",
"POSTING_DATE": "20211117",
"MARKET": "CME",
"TRADETYP": "EXP",
"MAX_DOC_QTY": "12256.230",
"TRANSPORT_CODE": "ES",
"DOCNR": "4700234521"
},
{
"DOC_QTY": "14256.210",
"ACT_NOM_CONSUMED_QTY": "0.000",
"REM_MAX_QTY_TE": "0.000",
"XMDOCNR": "5025023562",
"DOCITM": "0000012041",
"COMMODITY": "RB",
"TRADING_COMPANY": "3862",
"PERIODICITY": "PRAGUE",
"POSTING_DATE": "20211117",
"MARKET": "CME",
"TRADETYP": "SE",
"MAX_DOC_QTY": "14256.230",
"TRANSPORT_CODE": "AR",
"DOCNR": "4700278453"
}
],
"PACKAGE_SEQ_NBR": "1",
"PACKAGE_SEQ_MAX_NBR": "1"
}
}
}
}
DESIRED JSON
[{
"TRADERECORD": {
"DOC_QTY": "19956.930",
"ACT_NOM_CONSUMED_QTY": "0.000",
"REM_MAX_QTY_TE": "0.000",
"XMDOCNR": "5025087976",
"DOCITM": "0000012001",
"COMMODITY": "RB",
"TRADING_COMPANY": "3862",
"PERIODICITY": "PRAGUE",
"POSTING_DATE": "20211117",
"MARKET": "CME",
"TRADETYP": "GR",
"MAX_DOC_QTY": "19956.930",
"TRANSPORT_CODE": "BARGE",
"DOCNR": "4700253115",
"SEGMENTH": "1",
"TRADE_NUM": "NA-152",
"PACKAGE_GUID": "ASDER3785$%SDF",
"TRADETYP_TCODE_ALL": ["GR-BARGE", "EXP-AR", "CR-LCL"]
}
},
{
"TRADERECORD": {
"DOC_QTY": "12256.230",
"ACT_NOM_CONSUMED_QTY": "0.000",
"REM_MAX_QTY_TE": "0.000",
"XMDOCNR": "5025092776",
"DOCITM": "0000014021",
"COMMODITY": "RB",
"TRADING_COMPANY": "3862",
"PERIODICITY": "PRAGUE",
"POSTING_DATE": "20211117",
"MARKET": "CME",
"TRADETYP": "EXP",
"MAX_DOC_QTY": "12256.230",
"TRANSPORT_CODE": "AR",
"DOCNR": "4700234521",
"SEGMENTH": "1",
"TRADE_NUM": "NA-152",
"PACKAGE_GUID": "ASDER3785$%SDF",
"TRADETYP_TCODE_ALL": ["GR-BARGE", "EXP-AR", "CR-LCL"]
}
},
{
"TRADERECORD": {
"DOC_QTY": "14256.210",
"ACT_NOM_CONSUMED_QTY": "0.000",
"REM_MAX_QTY_TE": "0.000",
"XMDOCNR": "5025023562",
"DOCITM": "0000012041",
"COMMODITY": "RB",
"TRADING_COMPANY": "3862",
"PERIODICITY": "PRAGUE",
"POSTING_DATE": "20211117",
"MARKET": "CME",
"TRADETYP": "CR",
"MAX_DOC_QTY": "14256.230",
"TRANSPORT_CODE": "LCL",
"DOCNR": "4700278453",
"SEGMENTH": "1",
"TRADE_NUM": "NA-152",
"PACKAGE_GUID": "ASDER3785$%SDF",
"TRADETYP_TCODE_ALL": ["GR-BARGE", "EXP-AR", "CR-LCL"]
}
}
]
The Jolt Spec I am working on :
[
{
"operation": "shift",
"spec": {
"TRADE_HEADER": {
"TRADEDETAIL": {
"TRADEDETAILLINE": {
"*": {
"@": "[&1]",
"@(2,SEGMENT)": "[&1].SEGMENTH",
"@(2,TRADE_NUM)": "[&1].TRADE_NUM",
"@(2,PACKAGE_GUID)": "[&1].PACKAGE_GUID",
"@(0,TRADETYP)": "[#1].TRADETYP_ALL",
"@(0,TRANSPORT_CODE)": "[#1].TRANSPORT_CODE_ALL"
}
}
}
}
}
},
{
"operation": "shift",
"spec": {
"*": {
"@": "TRADERECORD"
}
}
}
]
The Result of this Jolt spec
{
"TRADERECORD" : [ {
"DOC_QTY" : "19956.930",
"ACT_NOM_CONSUMED_QTY" : "0.000",
"REM_MAX_QTY_TE" : "0.000",
"XMDOCNR" : "5025087976",
"DOCITM" : "0000012001",
"COMMODITY" : "RB",
"TRADING_COMPANY" : "3862",
"PERIODICITY" : "PRAGUE",
"POSTING_DATE" : "20211117",
"MARKET" : "CME",
"TRADETYP" : "GR",
"MAX_DOC_QTY" : "19956.930",
"TRANSPORT_CODE" : "BARGE",
"DOCNR" : "4700253115",
"SEGMENTH" : "1",
"TRADE_NUM" : "NA-152",
"PACKAGE_GUID" : "ASDER3785$%SDF",
"TRADETYP_ALL" : [ "GR", "EXP", "CR" ],
"TRANSPORT_CODE_ALL" : [ "BARGE", "AR", "LCL" ]
}, {
"DOC_QTY" : "12256.230",
"ACT_NOM_CONSUMED_QTY" : "0.000",
"REM_MAX_QTY_TE" : "0.000",
"XMDOCNR" : "5025092776",
"DOCITM" : "0000014021",
"COMMODITY" : "RB",
"TRADING_COMPANY" : "3862",
"PERIODICITY" : "PRAGUE",
"POSTING_DATE" : "20211117",
"MARKET" : "CME",
"TRADETYP" : "EXP",
"MAX_DOC_QTY" : "12256.230",
"TRANSPORT_CODE" : "AR",
"DOCNR" : "4700234521",
"SEGMENTH" : "1",
"TRADE_NUM" : "NA-152",
"PACKAGE_GUID" : "ASDER3785$%SDF"
}, {
"DOC_QTY" : "14256.210",
"ACT_NOM_CONSUMED_QTY" : "0.000",
"REM_MAX_QTY_TE" : "0.000",
"XMDOCNR" : "5025023562",
"DOCITM" : "0000012041",
"COMMODITY" : "RB",
"TRADING_COMPANY" : "3862",
"PERIODICITY" : "PRAGUE",
"POSTING_DATE" : "20211117",
"MARKET" : "CME",
"TRADETYP" : "CR",
"MAX_DOC_QTY" : "14256.230",
"TRANSPORT_CODE" : "LCL",
"DOCNR" : "4700278453",
"SEGMENTH" : "1",
"TRADE_NUM" : "NA-152",
"PACKAGE_GUID" : "ASDER3785$%SDF"
} ]
}
Please help me combining the attributes and get to the final desired JSON output