我正在尝试在NIFI中创建一个jolt转换,我有一个带有标题、细节和行细节的JSON消息作为带有行细节对象的数组。
我们可以将标头/详细JSON转换为详细JSON吗?每个详细都有一个单独的JSON,带有2个新标签,具有“TRADETYP”和“TRANSPORT_CODE”的详细属性值的扁平数组
"TRADETYPALLLINES":["GR"、"EXP"、"SE"]"TRANSPORT_CODE_ALLLINES":["BARGE"、"ES"、"AR"]
这是示例 JSON:
{
"TRADE_HEADER": {
"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"
}
}
}
所需的JSON:
[
{
"TRADERECORD": {
"TRADE_NUM": "NA-152",
"PACKAGE_GUID": "ASDER3785$%SDF",
"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",
"TRADETYPALLLINES": [
"GR",
"EXP",
"SE"
],
"TRANSPORT_CODE_ALLLINES": [
"BARGE",
"ES",
"AR"
]
}
},
{
"TRADERECORD": {
"TRADE_NUM": "NA-152",
"PACKAGE_GUID": "ASDER3785$%SDF",
"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",
"TRADETYPALLLINES": [
"GR",
"EXP",
"SE"
],
"TRANSPORT_CODE_ALLLINES": [
"BARGE",
"ES",
"AR"
]
}
},
{
"TRADERECORD": {
"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": "SE",
"MAX_DOC_QTY": "14256.230",
"TRANSPORT_CODE": "AR",
"DOCNR": "4700278453",
"TRADETYPALLLINES": [
"GR",
"EXP",
"SE"
],
"TRANSPORT_CODE_ALLLINES": [
"BARGE",
"ES",
"AR"
]
}
}
]
这是我得到的颠簸规格:
[
{
"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"
}
}
}
]
该规范的结果:
{
"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"
} ]
}
如何在所有详细记录中重复“TRADETYP_ALL”和“TRANSPORT_CODE_ALL”
我还想添加另一个标签“TRADETYP_CODE_ALL”,将“TRADET_ALL”和“TRANSPORT_CODE_ELL”的值组合在一起
" TRADETYP_CODE_ALL" : [ "GR-BARGE "," EXP-AR "," CR-LCL" ]
感谢任何这方面的帮助。
到目前为止还不错,只需要添加一个修改转换规范,例如
[
{
"operation": "shift",
"spec": {
"TRADE*": {
"TRADE*": {
"TRADE*": {
"*": {
"@": "a[&1].TRADERECORD",
"@(2,TRADE_NUM)": "a[&1].TRADERECORD.TRADE_NUM",
"@(2,PACKAGE_GUID)": "a[&1].TRADERECORD.PACKAGE_GUID",
"@(0,TRADETYP)": "b[#1].TRADETYPALLLINES",
"@(0,TRANSPORT_CODE)": "b[#1].TRANSPORT_CODE_ALLLINES"
}
}
}
}
}
},
{
"operation": "modify-overwrite-beta",
"spec": {
"a": {
"*": {
"TRADER*": {
"TRADETYPALLLINES": "@(4,b[0].TRADETYPALLLINES)",
"TRANSPORT_CODE_ALLLINES": "@(4,b[0].TRANSPORT_CODE_ALLLINES)"
}
}
}
}
},
{
// get rid of object labels
"operation": "shift",
"spec": {
"a": {
"*": ""
}
}
}
]
该网站上的演示http://jolt-demo.appspot.com/是:
编辑:如果你还需要添加一个新的属性
(即:“TRADETYP_TCODE_ALL”:[“GR-BARGE”、“EXP-AR”、“CR-LCL”]
)
由新创建的数组的串联组件组成,然后使用
以下一个:
[
{
"operation": "shift",
"spec": {
"TRADE*": {
"TRADE*": {
"TRADE*": {
"*": {
"@": "a[&1].TRADERECORD",
"@(2,TRADE_NUM)": "a[&1].TRADERECORD.TRADE_NUM",
"@(2,PACKAGE_GUID)": "a[&1].TRADERECORD.PACKAGE_GUID",
"@(0,TRADETYP)": "b[#1].TRADETYPALLLINES",
"@(0,TRANSPORT_CODE)": "b[#1].TRANSPORT_CODE_ALLLINES"
}
}
}
}
}
},
{
"operation": "modify-overwrite-beta",
"spec": {
"a": {
"*": {
"TRADER*": {
"TRADETYPALLLINES": "@(4,b[0].TRADETYPALLLINES)",
"TRANSPORT_CODE_ALLLINES": "@(4,b[0].TRANSPORT_CODE_ALLLINES)"
}
}
}
}
},
{
"operation": "shift",
"spec": {
"a": {
"*": "&1.&"
},
"b": {
"*": {
"TRADETYPALLLINES": { "*": "&3.&" },
"TRANSPORT_CODE_ALLLINES": { "*": "&3.&" }
}
}
}
},
{
"operation": "modify-overwrite-beta",
"spec": {
"b": {
"*": "=join('-',@(1,&))"
}
}
},
{
"operation": "shift",
"spec": {
"a": {
"*": "&1.&"
},
"b": {
"*": "TRADETYP_TCODE_ALL"
}
}
},
{
"operation": "shift",
"spec": {
"a": {
"*": {
"@": "&",
"@(2,TRADETYP_TCODE_ALL)": "&1.TRADERECORD.TRADETYP_TCODE_ALL"
}
}
}
},
{
// get rid of object labels
"operation": "shift",
"spec": {
"*": ""
}
}
]
我正在尝试为以下输入创建震动转换: 所需输出为: 我刚刚开始理解jolt转换的基础,但是对于嵌套结构来说,这似乎有点复杂。
我正在尝试转换一个包含数组的JSON对象,并将数据卸载为单独的JSON。基本上,我需要为数组的每个元素创建一个对象,并复制所有外部数据。示例: 输入 预期产出 我尝试的规格: 我对 Jolt 很陌生,并尝试了几个不起作用的规格。我在取消嵌套部分时遇到问题。谢谢你的帮助。
我需要Jolt转换的帮助。我有数组,由许多json对象组成。(https://jolt-demo.appspot.com/) Jolt需要进行哪些转换才能获得以下结果? 现在我有了下一个Jolt构造: 但以下结果不正确:
我已经将一个jso转换为另一个json。一切看起来都很好。除了下面的场景。 输入Json: 预期的JSON: 有人能帮我写这个转换的规范吗?
我正在尝试为下面的输入编写一个震动转换 - 预期产量为- 我的规格是- 规范没有按照预期的输出进行转换。我想学习如何在字符串解析器中使用属性。
我有一个问题与我的震动转换,但不知道如何解决它。我在生成的数组中获得“null”元素: 我的结果: