[英]I am trying to write a jolt transformation for below input -
這是一個輸入,需要使用 Jolt Transformation 進行轉換以獲得預期的 output。
我正在嘗試為以下輸入編寫一個顛簸轉換。 但它與預期的 output 不匹配。
我的輸入:
[
{
"external_id": 855644012615,
"order_id": 4551472709703,
"processed_at": "2022-08-30T02:40:26-04:00",
"tracking_number": 4.201110410179302e+24,
"refund_line_items": [
{
"order_line_item_id": 11544859803719,
"quantity": 6,
"line_item": {
"name": "FLORENCIA RED MULTI - RED MULTI / 6 / 634",
"product_id": 6586562773063,
"properties": [
{
"name": "UPCA",
"value": "195945037714"
}
]
}
}
]
}
]
預計 output
[
{
"externalId" : 855644012615,
"orderExternalId" : 4551472709703,
"partyIdFrom" : "NA",
"destinationFacilityId" : "",
"partyIdTo" : "NA",
"status" : "PURCH_SHIP_CREATED",
"type" : "SALES_RETURN",
"estimatedShipCost" : "0",
"packages" : [
{
"packageSeqId" : "",
"trackingCode" : 4.201110410179302E24,
"items" : [
{
"sku" : "195945037714",
"quantity" : 6
}
]
}
]
}
]
我正在使用此規范來轉換輸入 JSON。 你能幫忙找出我的錯誤嗎?
[
{
"operation": "default",
"spec": {
"*": {
"partyIdFrom": "_NA_",
"destinationFacilityId": "",
"externalPartyIdFrom": "",
"partyIdTo": "_NA_",
"status": "PURCH_SHIP_CREATED",
"type": "SALES_RETURN",
"estimatedShipCost": "0",
"packageSeqId": ""
}
}
},
{
"operation": "shift",
"spec": {
"*": {
"external_id": "[&1].externalId",
"order_id": "[&1].orderExternalId",
"partyIdFrom": "[&1].partyIdFrom",
"destinationFacilityId": "[&1].destinationFacilityId",
"partyIdTo": "[&1].partyIdTo",
"status": "[&1].status",
"type": "[&1].type",
"estimatedShipCost": "[&1].estimatedShipCost",
"packageSeqId": "[&1].packages[&1].packageSeqId",
"tracking_number": "[&1].packages[&1].trackingCode",
"refund_line_items": {
"*": {
"quantity": "[&2].packages[#5].items[&3].quantity",
"line_item": {
"properties": {
"*": {
"value": "[&6].packages[#4].items[&1].sku"
}
}
}
}
}
}
}
}
]
到目前為止一切順利,只需要添加行
"@(3,quantity)": "[&6].packages[#4].items[&1].quantity"
進入"properties"
object,並將某些屬性的葉節點替換為&
字符以復制它們的鍵名。 例如,無需重復編寫它們。 這些鍵值對是:
"partyIdFrom": "[&1].&",
"destinationFacilityId": "[&1].&",
"partyIdTo": "[&1].&",
"status": "[&1].&",
"type": "[&1].&",
"estimatedShipCost": "[&1].&",
"packageSeqId": "[&1].packages[&1].&",
確實只使用了一行
"*": "[&1].&",
就足夠了,但這種情況下的順序會混淆。
因此,更喜歡使用以下轉換規范:
[
{
"operation": "default",
"spec": {
"*": {
"partyIdFrom": "_NA_",
"destinationFacilityId": "",
"externalPartyIdFrom": "",
"partyIdTo": "_NA_",
"status": "PURCH_SHIP_CREATED",
"type": "SALES_RETURN",
"estimatedShipCost": "0",
"packageSeqId": ""
}
}
},
{
"operation": "shift",
"spec": {
"*": {
"external_id": "[&1].externalId",
"order_id": "[&1].orderExternalId",
"partyIdFrom": "[&1].&", //should be converted to this
"destinationFacilityId": "[&1].&", //should be converted to this
"partyIdTo": "[&1].&", //should be converted to this
"status": "[&1].&", //should be converted to this
"type": "[&1].&", //should be converted to this
"estimatedShipCost": "[&1].&", //should be converted to this
"packageSeqId": "[&1].packages[&1].&", //should be converted to this
"tracking_number": "[&1].packages[&1].trackingCode",
"refund_line_items": {
"*": {
"quantity": "[&2].packages[#5].items[&3].&",
"line_item": {
"properties": {
"*": {
"value": "[&6].packages[#4].items[&1].sku",
"@(3,quantity)": "[&6].packages[#4].items[&1].quantity" //should be added
}
}
}
}
}
}
}
}
]
順便說一句,另一種選擇是使用#
通配符,如以下示例行所示
"#PURCH_SHIP_CREATED": "[&1].status",
通過使用這種方式,不需要默認的轉換規范。
我預期的輸入 JSON 的最終答案。
[
{
"operation": "default",
"spec": {
"*": {
"partyIdFrom": "_NA_",
"destinationFacilityId": "",
"externalPartyIdFrom": "",
"partyIdTo": "_NA_",
"status": "PURCH_SHIP_CREATED",
"type": "SALES_RETURN",
"estimatedShipCost": "0",
"packageSeqId": ""
}
}
}, {
"operation": "shift",
"spec": {
"*": {
"external_id": "[&1].externalId",
"order_id": "[&1].orderExternalId",
"partyIdFrom": "[&1].partyIdFrom",
"destinationFacilityId": "[&1].destinationFacilityId",
"partyIdTo": "[&1].partyIdTo",
"status": "[&1].status",
"type": "[&1].type",
"estimatedShipCost": "[&1].estimatedShipCost",
"packageSeqId": "[&1].packages[#3].packageSeqId",
"tracking_number": "[&1].packages[#3].trackingCode",
"refund_line_items": {
"*": {
"quantity": "[&3].packages[#5].items[#2].quantity",
"line_item": {
"properties": {
"*": {
"value": "[&6].packages[#8].items[#5].sku"
}
}
}
}
}
}
}
}
]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.