多输入的通用 Jolt 规格 JSON

Generic Jolt Spec for Multiple Input JSON

我很难为不同的 JSON 输入编写震动规范。我需要一个通用的颠簸规格,这样我才能得到一个扁平的 json

输入 1 :

[
  {
    "OrderInfo": [
      {
        "OrderHeader": {
          "orderType": "PULL",
          "customerPOType": "",
          "enteredDate": "20220324190249",
          "mitSect": "",
          "mitBillingFacility": "",
          "customerCode": "Z177",
          "mitAccNo": "",
          "userCWSId": "ANDERM2",
          "userName": "Michael Andersen",
          "rushFlag": 0,
          "customerPONumber": "",
          "mitPriorityIndicator": "",
          "mitOrderNumber": "",
          "customerFacilityCode": "JA",
          "GSIOrderNumber": "SHIVAM1000000100",
          "dtCode": "JADOJA",
          "mitRemarks": ""
        },
        "OrderDetails": [
          {
            "deliverToCoordinates": " SUPRA2RA",
            "exactQuantityFlag": "",
            "earlyShipDate": "20220324190249",
            "deliverToDockBuilding": "JA",
            "preferredWarehouseId": "SE92",
            "deliverToBuilding": "A2",
            "deliverToDropZoneArea": " A2A",
            "orderQuantity": 100,
            "orderMethod": "P",
            "plannedFirmIndicator": "F",
            "transactionType": "A",
            "lateShipDate": "",
            "crossdockFlag": 0,
            "deliverToArea": " A2A",
            "partNumber": "2T3001",
            "buildSequenceNumber": "",
            "deliverToDropZoneBuilding": "A2",
            "orderLineNumber": 1,
            "deliverToDockArea": "DOJA"
          }
        ]
      },
      {
        "OrderHeader": {
          "orderType": "PULL",
          "customerPOType": "",
          "enteredDate": "20220324190249",
          "mitSect": "",
          "mitBillingFacility": "",
          "customerCode": "Z177",
          "mitAccNo": "",
          "userCWSId": "ANDERM2",
          "userName": "Michael Andersen",
          "rushFlag": 0,
          "customerPONumber": "",
          "mitPriorityIndicator": "",
          "mitOrderNumber": "",
          "customerFacilityCode": "JA",
          "GSIOrderNumber": "SHIVAM1000000100",
          "dtCode": "JADOJA",
          "mitRemarks": ""
        },
        "OrderDetails": [
          {
            "deliverToCoordinates": " SUPRA2RA",
            "exactQuantityFlag": "",
            "earlyShipDate": "20220324190249",
            "deliverToDockBuilding": "JA",
            "preferredWarehouseId": "SE92",
            "deliverToBuilding": "A2",
            "deliverToDropZoneArea": " A2A",
            "orderQuantity": 100,
            "orderMethod": "P",
            "plannedFirmIndicator": "F",
            "transactionType": "A",
            "lateShipDate": "",
            "crossdockFlag": 0,
            "deliverToArea": " A2A",
            "partNumber": "2T3001",
            "buildSequenceNumber": "",
            "deliverToDropZoneBuilding": "A2",
            "orderLineNumber": 1,
            "deliverToDockArea": "DOJA"
          }
        ]
      }
    ]
  }
]

输入 2 :

[
  {
    "OrderInfo": [
      {
        "OrderHeader": {
          "orderType": "MCOE",
          "esoNumber": "TLVKK00",
          "rushFlag": "0",
          "serialNumber": "CA900319",
          "enteredDate": "20220110082146",
          "customerFacilityCode": "LE",
          "GSIOrderNumber": "DS0000000055068",
          "customerCode": "Z319"
        },
        "OrderDetails": [
          {
            "deliverToCoordinates": "S-X=ILCMC ",
            "exactQuantityFlag": "Y",
            "earlyShipDate": "20220110082146",
            "deliverToDockBuilding": "LE",
            "kanbanNumber": "SAMG 047877",
            "preferredWarehouseId": "",
            "deliverToBuilding": "B",
            "buildDate": "20211208000000",
            "deliverToDropZoneArea": "04M",
            "orderQuantity": 8,
            "startOnLineDate": "20211207000000",
            "warehouseId": "",
            "crossdockFlag": 0,
            "deliverToArea": "04M",
            "partNumber": "7K1181",
            "buildSequenceNumber": "012",
            "deliverToDropZoneBuilding": "B ",
            "orderLineNumber": 90,
            "deliverToDockArea": "DOCK"
          },
          {
            "deliverToCoordinates": "S-X=ILCMC ",
            "exactQuantityFlag": "Y",
            "earlyShipDate": "20220110082146",
            "deliverToDockBuilding": "LE",
            "kanbanNumber": "SAMG 020472",
            "preferredWarehouseId": "",
            "deliverToBuilding": "B",
            "buildDate": "20211208000000",
            "deliverToDropZoneArea": "04M",
            "orderQuantity": 4,
            "startOnLineDate": "20211207000000",
            "warehouseId": "",
            "crossdockFlag": 0,
            "deliverToArea": "04M",
            "partNumber": "6V8398",
            "buildSequenceNumber": "012",
            "deliverToDropZoneBuilding": "B ",
            "orderLineNumber": 173,
            "deliverToDockArea": "DOCK"
          }
        ]
      }
    ]
  }
]

JSON 需要输出 -

单个扁平化 JSON :

[
  {
    "GSIOrderNumber": "SHIVAM1000000100",
    "Orderdetails.deliverToCoordinates": " SUPRA2RA",
    "Orderdetails.exactQuantityFlag": "",
    "Orderdetails.earlyShipDate": "20220324190249",
    "Orderdetails.deliverToDockBuilding": "JA",
    "Orderdetails.preferredWarehouseId": "SE92",
    "Orderdetails.deliverToBuilding": "A2",
    "Orderdetails.deliverToDropZoneArea": " A2A",
    "Orderdetails.orderQuantity": 100,
    "Orderdetails.orderMethod": "P",
    "Orderdetails.plannedFirmIndicator": "F",
    "Orderdetails.transactionType": "A",
    "Orderdetails.lateShipDate": "",
    "Orderdetails.crossdockFlag": 0,
    "Orderdetails.deliverToArea": " A2A",
    "Orderdetails.partNumber": "2T3001",
    "Orderdetails.buildSequenceNumber": "",
    "Orderdetails.deliverToDropZoneBuilding": "A2",
    "Orderdetails.orderLineNumber": 1,
    "Orderdetails.deliverToDockArea": "DOJA"
  }
]

Jolt Spec i Tried 适用于输入 2 但不适用于输入 1:

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "OrderInfo": {
          "*": {
            "OrderDetails": {
              "*": {
                "@(2,OrderHeader.GSIOrderNumber)": "[&].GSIOrderNumber",
                "*": "[&1].Orderdetails\.&"
              }
            }
          }
        }
      }
    }
  }
]

请帮助我在为不同的 JSON 输入编写震动规范时遇到困难。我需要一个通用的颠簸规格,这样我才能得到一个扁平的 json

以下移位转换规范将为每个输入产生所需的输出

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "OrderInfo": {
          "*": {
            "OrderDetails": {
              "*": {
                "@(2,OrderHeader.GSIOrderNumber)": "[&3].&1.GSIOrderNumber",
                "*": "[&3].&1.&"
              }
            }
          }
        }
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": ""
      }
    }
  }
]

再添加一层(通过使用&1),并在更高层次上分离对象(通过使用[&3]),然后去掉最后一层中的对象键规格