从数组中提取product.code到Apache NiFi中的新数组

问题描述 投票:0回答:1

晚安!

我有一个包含这些数组项的 json:

{
  "items": [
    {
      "organization": "900",
      "identifier": 68693000000025,
      "positionItem": 3,
      "percentagePis": 0,
      "percentageCofins": 0,
      "itemNumber": 1,
      "entryDate": "09/02/2024",
      "deliveryDate": "14/02/2024",
      "product": {
        "organization": "900",
        "code": 1068
      },
      "cfopCode": {
        "cfopCode": 5101,
        "cfopSequence": 0
      },
      "cfopSequence": 0,
      "quantity": 10,
      "stockUnit": {
        "organization": "900",
        "unit": "UN"
      },
      "weight": 0.2,
      "packing": {
        "code": 5
      },
      "priceList": 1014,
      "price": 3.86,
      "standardPrice": 3.86,
      "unitCost": 0,
      "productReference": "1068",
      "productDescription": "BDJA MOLEQUINHO GUIMARAES 200",
      "purschaseOrder": "",
      "itemPurchaseOrder": 0,
      "externalIdOrder": 0,
      "combination": 0,
      "originOfGoods": 0,
      "movimentedBatch": null,
      "stockLocation": null,
      "firstPercentageDiscount": 0,
      "secondPercentageDiscount": 0,
      "thirdPercentageDiscount": 0,
      "fourthPercentageDiscount": 0,
      "fifthPercentageDiscount": 0,
      "percentageIncrease": 0,
      "icmtCst": 41,
      "percentageIcms": 17,
      "percentageIpi": 0,
      "taxSituationPis": 7,
      "taxSituationCofins": 7,
      "taxSituationIpi": 53,
      "simplesNacionalOperationCode": 999,
      "grossAmount": 38.6,
      "discountAmount": 0,
      "totalNetAmount": 38.6,
      "issPercentageRetained": 0,
      "perIcmsSubstituteBaseReduction": 0,
      "freightAmount": 0,
      "insuranceAmount": 0,
      "ancillaryExpensesAmount": 0,
      "individualPackageType": {
        "code": 2
      },
      "issPercentageNotRetained": 0,
      "numberOfLabels": 1,
      "itemIdObservation": null,
      "productionIdObservation": null,
      "lastChangeDate": "14/02/2024",
      "lastChangeTime": 181720,
      "formattedLastChangeTime": "18:17:20",
      "labelApportionment": [],
      "itemsProductionOrders": []
    },
    {
      "organization": "900",
      "identifier": 68693000000026,
      "positionItem": 3,
      "percentagePis": 0,
      "percentageCofins": 0,
      "itemNumber": 2,
      "entryDate": "09/02/2024",
      "deliveryDate": "14/02/2024",
      "product": {
        "organization": "900",
        "code": 1109
      },
      "cfopCode": {
        "cfopCode": 5101,
        "cfopSequence": 0
      },
      "cfopSequence": 0,
      "quantity": 25,
      "stockUnit": {
        "organization": "900",
        "unit": "UN"
      },
      "weight": 0.12,
      "packing": {
        "code": 5
      },
      "priceList": 1014,
      "price": 2.09,
      "standardPrice": 2.09,
      "unitCost": 0,
      "productReference": "1109",
      "productDescription": "AMENDOIM CARA PINA 120G",
      "purschaseOrder": "",
      "itemPurchaseOrder": 0,
      "externalIdOrder": 0,
      "combination": 0,
      "originOfGoods": 0,
      "movimentedBatch": null,
      "stockLocation": null,
      "firstPercentageDiscount": 0,
      "secondPercentageDiscount": 0,
      "thirdPercentageDiscount": 0,
      "fourthPercentageDiscount": 0,
      "fifthPercentageDiscount": 0,
      "percentageIncrease": 0,
      "icmtCst": 41,
      "percentageIcms": 17,
      "percentageIpi": 0,
      "taxSituationPis": 7,
      "taxSituationCofins": 7,
      "taxSituationIpi": 53,
      "simplesNacionalOperationCode": 999,
      "grossAmount": 52.25,
      "discountAmount": 0,
      "totalNetAmount": 52.25,
      "issPercentageRetained": 0,
      "perIcmsSubstituteBaseReduction": 0,
      "freightAmount": 0,
      "insuranceAmount": 0,
      "ancillaryExpensesAmount": 0,
      "individualPackageType": {
        "code": 2
      },
      "issPercentageNotRetained": 0,
      "numberOfLabels": 1,
      "itemIdObservation": null,
      "productionIdObservation": null,
      "lastChangeDate": "14/02/2024",
      "lastChangeTime": 181720,
      "formattedLastChangeTime": "18:17:20",
      "labelApportionment": [],
      "itemsProductionOrders": []
    },
    {
      "organization": "900",
      "identifier": 68693000000027,
      "positionItem": 3,
      "percentagePis": 0,
      "percentageCofins": 0,
      "itemNumber": 3,
      "entryDate": "09/02/2024",
      "deliveryDate": "14/02/2024",
      "product": {
        "organization": "900",
        "code": 1029
      },
      "cfopCode": {
        "cfopCode": 5101,
        "cfopSequence": 0
      },
      "cfopSequence": 0,
      "quantity": 20,
      "stockUnit": {
        "organization": "900",
        "unit": "UN"
      },
      "weight": 0.2,
      "packing": {
        "code": 11
      },
      "priceList": 1014,
      "price": 3.95,
      "standardPrice": 3.95,
      "unitCost": 0,
      "productReference": "1029",
      "productDescription": "AMENDOIM CARA PINA 200 GR",
      "purschaseOrder": "",
      "itemPurchaseOrder": 0,
      "externalIdOrder": 0,
      "combination": 0,
      "originOfGoods": 0,
      "movimentedBatch": null,
      "stockLocation": null,
      "firstPercentageDiscount": 0,
      "secondPercentageDiscount": 0,
      "thirdPercentageDiscount": 0,
      "fourthPercentageDiscount": 0,
      "fifthPercentageDiscount": 0,
      "percentageIncrease": 0,
      "icmtCst": 41,
      "percentageIcms": 17,
      "percentageIpi": 0,
      "taxSituationPis": 7,
      "taxSituationCofins": 7,
      "taxSituationIpi": 53,
      "simplesNacionalOperationCode": 999,
      "grossAmount": 79,
      "discountAmount": 0,
      "totalNetAmount": 79,
      "issPercentageRetained": 0,
      "perIcmsSubstituteBaseReduction": 0,
      "freightAmount": 0,
      "insuranceAmount": 0,
      "ancillaryExpensesAmount": 0,
      "individualPackageType": {
        "code": 2
      },
      "issPercentageNotRetained": 0,
      "numberOfLabels": 1,
      "itemIdObservation": null,
      "productionIdObservation": null,
      "lastChangeDate": "14/02/2024",
      "lastChangeTime": 181720,
      "formattedLastChangeTime": "18:17:20",
      "labelApportionment": [],
      "itemsProductionOrders": []
    },
    {
      "organization": "900",
      "identifier": 68693000000028,
      "positionItem": 3,
      "percentagePis": 0,
      "percentageCofins": 0,
      "itemNumber": 4,
      "entryDate": "09/02/2024",
      "deliveryDate": "14/02/2024",
      "product": {
        "organization": "900",
        "code": 1053
      },
      "cfopCode": {
        "cfopCode": 5101,
        "cfopSequence": 0
      },
      "cfopSequence": 0,
      "quantity": 12,
      "stockUnit": {
        "organization": "900",
        "unit": "UN"
      },
      "weight": 0.125,
      "packing": {
        "code": 5
      },
      "priceList": 1014,
      "price": 2.99,
      "standardPrice": 2.99,
      "unitCost": 0,
      "productReference": "1053",
      "productDescription": "AMENDOIM SALGADO 125 GR",
      "purschaseOrder": "",
      "itemPurchaseOrder": 0,
      "externalIdOrder": 0,
      "combination": 0,
      "originOfGoods": 0,
      "movimentedBatch": null,
      "stockLocation": null,
      "firstPercentageDiscount": 0,
      "secondPercentageDiscount": 0,
      "thirdPercentageDiscount": 0,
      "fourthPercentageDiscount": 0,
      "fifthPercentageDiscount": 0,
      "percentageIncrease": 0,
      "icmtCst": 41,
      "percentageIcms": 17,
      "percentageIpi": 0,
      "taxSituationPis": 7,
      "taxSituationCofins": 7,
      "taxSituationIpi": 53,
      "simplesNacionalOperationCode": 999,
      "grossAmount": 35.88,
      "discountAmount": 0,
      "totalNetAmount": 35.88,
      "issPercentageRetained": 0,
      "perIcmsSubstituteBaseReduction": 0,
      "freightAmount": 0,
      "insuranceAmount": 0,
      "ancillaryExpensesAmount": 0,
      "individualPackageType": {
        "code": 2
      },
      "issPercentageNotRetained": 0,
      "numberOfLabels": 1,
      "itemIdObservation": null,
      "productionIdObservation": null,
      "lastChangeDate": "14/02/2024",
      "lastChangeTime": 181720,
      "formattedLastChangeTime": "18:17:20",
      "labelApportionment": [],
      "itemsProductionOrders": []
    },
    {
      "organization": "900",
      "identifier": 68693000000049,
      "positionItem": 3,
      "percentagePis": 0,
      "percentageCofins": 0,
      "itemNumber": 25,
      "entryDate": "09/02/2024",
      "deliveryDate": "14/02/2024",
      "product": {
        "organization": "900",
        "code": 1098
      },
      "cfopCode": {
        "cfopCode": 5101,
        "cfopSequence": 0
      },
      "cfopSequence": 0,
      "quantity": 5,
      "stockUnit": {
        "organization": "900",
        "unit": "UN"
      },
      "weight": 0.25,
      "packing": {
        "code": 5
      },
      "priceList": 1014,
      "price": 5.93,
      "standardPrice": 5.93,
      "unitCost": 0,
      "productReference": "1098",
      "productDescription": "POTE DE MELADO BISNAGA 250GR",
      "purschaseOrder": "",
      "itemPurchaseOrder": 0,
      "externalIdOrder": 0,
      "combination": 0,
      "originOfGoods": 0,
      "movimentedBatch": null,
      "stockLocation": null,
      "firstPercentageDiscount": 0,
      "secondPercentageDiscount": 0,
      "thirdPercentageDiscount": 0,
      "fourthPercentageDiscount": 0,
      "fifthPercentageDiscount": 0,
      "percentageIncrease": 0,
      "icmtCst": 41,
      "percentageIcms": 17,
      "percentageIpi": 0,
      "taxSituationPis": 7,
      "taxSituationCofins": 7,
      "taxSituationIpi": 53,
      "simplesNacionalOperationCode": 999,
      "grossAmount": 29.65,
      "discountAmount": 0,
      "totalNetAmount": 29.65,
      "issPercentageRetained": 0,
      "perIcmsSubstituteBaseReduction": 0,
      "freightAmount": 0,
      "insuranceAmount": 0,
      "ancillaryExpensesAmount": 0,
      "individualPackageType": {
        "code": 2
      },
      "issPercentageNotRetained": 0,
      "numberOfLabels": 1,
      "itemIdObservation": null,
      "productionIdObservation": null,
      "lastChangeDate": "14/02/2024",
      "lastChangeTime": 181721,
      "formattedLastChangeTime": "18:17:21",
      "labelApportionment": [],
      "itemsProductionOrders": []
    }
  ]
}

我需要将所有 items.product.code 和 items.product.organization 转换为数组:

itens" : [ 
{
"produto": "code",
"empresa": "organization"
},
{
"produto": "code",
"empresa": "organization"
},
{
"produto": "code",
"empresa": "organization"
}
]

这是(items.product.organization 到 itens(array).empresa 和 items.product.code 到 itens(array).produto)

使用 produto 和 empresa 列将项目转换为 itens, 基本上就是这样了。

感谢您的帮助!

text apache-nifi
1个回答
0
投票

您可以通过在 JoltTransformJSON

 处理器中使用 
shift 转换规范来处理该问题,如下所示:

[
  {
    "operation": "shift",
    "spec": {
      "*ms": {
        "*": {
          "product": {
            "code": "&(3,1)ns[&2].produto",
            "organization": "&(3,1)ns[&2].empresa"
          }
        }
      }
    }
  }
]
© www.soinside.com 2019 - 2024. All rights reserved.