当前位置: 首页 > 知识库问答 >
问题:

多输入JSON的通用Jolt规范

冷英博
2023-03-14

我很难为不同的JSON输入编写一个jolt规范。我需要得到一个通用的jolt规范,以便得到一个扁平的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规范适用于输入2,但不适用于输入1:

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

请帮助我很难为不同的 JSON 输入编写颠簸规范。我需要获得一个通用的颠簸规范,以便我得到一个扁平化的 json

共有1个答案

干宏邈
2023-03-14

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

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

其中再添加一层(通过使用

 类似资料:
  • 我很难为不同的JSON输入编写jolt规范。我需要一个通用的jolt规范,这样我就可以得到一个扁平的json。 输入 1 : 我们有一个材料运动数组 输入2:我们没有物质运动数组 我已经为输入1使用了joltspec,它工作正常,我需要它也为输入2工作

  • 我对震动是新手。我有两个不同的相同结构的输入json集,除了一个对象内部不同的基于decider值,如下所示。

  • 我的输入JSON如下所示,但是我不确定如何使用JOLT进行内部数组相关的参数转换。感谢任何帮助,因为我是新的JOLT 以下是我创建的规范文件,但它并不完整 预期输出如下 我正在使用这个库https://github.com/bazaarvoice/jolt

  • 我正在努力使用 JOLT 转换复杂的 json。 输入JSON: 预期输出: 我无法理解如何在基于“字段名称”的输出中访问和分配“字段值”。请帮我做一下震动测试。 注意:输入JSON中的名称、标题和公司的顺序将是混乱和随机的,这意味着在“data”数组下,第一个对象仅与“Name”相关不是强制性的。

  • 我正在尝试用以下规格进行JOLT换班操作,这是不起作用的。不知道我犯了什么错误。在这种情况下需要帮助。输出JSON作为一个对象来代替Array,shift也不能按预期工作。

  • 我有以下输入json: 输出JSON应如下所示: 任何人都可以就如何为上述内容构建适当的 Bump 规范提供任何指导吗? 非常感谢您的帮助 ^_^