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

输入json所需的Jolt转换

秋阳荣
2023-03-14

我想用JOLT规范做JSON到JSON的转换。我有一个输入,它是Flattern JSOn,我想把它隐藏到嵌套JSOn中。我已经为此编写了JOLT规范,下面提到了它。但它并没有给出我所期望的输出。

{
  "gsiOrderNumber" : "1234567890",
  "orderType" : "PULL",
  "enteredDate" : "20200513021720",
  "customerFacilityCode" : "WK",
  "customerCode" : "Y302",
  "preferredWarehouseId" : "MWLC",
  "warehouseId" : "MWLC",
  "dtCode" : "DT",
  "customerPoNumber" : "PO123",
  "customerPoType" : "POType",
  "rushFlag" : "1",
  "esoNumber" : "SZXMF00",
  "serialNumber" : "CP900324",
  "mitSect" : "39704",
  "mitAccNo" : "1023",
  "mitOrderNumber" : "36560",
  "mitRemarks" : "MIT/41 UPSGRND",
  "mitPriorityIndicator" : "Y",
  "mitBillingFacility" : "12345",
  "OrderDetail" : [ {
    "gsiOrderNumber" : "000001234567890",
    "orderLineNumber" : "225266301",
    "partNumber" : "9780312606121",
    "orderQuantity" : "4",
    "exactQuantityFlag" : "F",
    "earlyShipDate" : "20200513021720",
    "lateShipDate" : "20200513021720",
    "orderMethod" : "P",
    "deliverToDockBuilding" : "H",
    "deliverToDockArea" : "H",
    "deliverToBuilding" : "H",
    "deliverToArea" : "07D",
    "deliverToCoordinates" : "H07DBR1702",
    "deliverToDropZoneBuilding" : "HZ",
    "deliverToDropZoneArea" : "HZ",
    "jitCallNumber" : "1234",
    "kanbanNumber" : "1234",
    "startOnLineDate" : "20200513021720",
    "buildDate" : "20200513021720",
    "transactionNumber" : "1234101"
  }, {
    "gsiOrderNumber" : "000001234567890",
    "orderLineNumber" : "225266301",
    "partNumber" : "9780312606121",
    "orderQuantity" : "4",
    "exactQuantityFlag" : "F",
    "earlyShipDate" : "20200513021720",
    "lateShipDate" : "20200513021720",
    "orderMethod" : "P",
    "deliverToDockBuilding" : "H",
    "deliverToDockArea" : "H",
    "deliverToBuilding" : "H",
    "deliverToArea" : "07D",
    "deliverToCoordinates" : "H07DBR1702",
    "deliverToDropZoneBuilding" : "HZ",
    "deliverToDropZoneArea" : "HZ",
    "jitCallNumber" : "1234",
    "kanbanNumber" : "1234",
    "startOnLineDate" : "20200513021720",
    "buildDate" : "20200513021720",
    "transactionNumber" : "1234101"
  } ]
}
{
  "OrderInfo": [
    {
      "OrderHeader": {
        "gsiOrderNumber": "1234567890",
        "orderType": "PULL",
        "enteredDate": "20200513021720",
        "customerFacilityCode": "WK",
        "customerCode": "Y302",
        "preferredWarehouseId": "MWLC",
        "warehouseId": "MWLC",
        "dtCode": "DT",
        "customerPoNumber": "PO123",
        "customerPoType": "POType",
        "rushFlag": "1",
        "esoNumber": "SZXMF00",
        "serialNumber": "CP900324",
        "mitSect": "39704",
        "mitAccNo": "1023",
        "mitOrderNumber": "36560",
        "mitRemarks": "MIT/41 UPSGRND",
        "mitPriorityIndicator": "Y",
        "mitBillingFacility": "12345"
      },
      "OrderDetail": [
        {
          "gsiOrderNumber": "000001234567890",
          "orderLineNumber": "225266301",
          "partNumber": "9780312606121",
          "orderQuantity": "4",
          "exactQuantityFlag": "F",
          "earlyShipDate": "20200513021720",
          "lateShipDate": "20200513021720",
          "orderMethod": "P",
          "deliverToDockBuilding": "H",
          "deliverToDockArea": "H",
          "deliverToBuilding": "H",
          "deliverToArea": "07D",
          "deliverToCoordinates": "H07DBR1702",
          "deliverToDropZoneBuilding": "HZ",
          "deliverToDropZoneArea": "HZ",
          "jitCallNumber": "1234",
          "kanbanNumber": "1234",
          "startOnLineDate": "20200513021720",
          "buildDate": "20200513021720",
          "transactionNumber": "1234101"
        },
        {
          "gsiOrderNumber": "000001234567890",
          "orderLineNumber": "225266301",
          "partNumber": "9780312606121",
          "orderQuantity": "4",
          "exactQuantityFlag": "F",
          "earlyShipDate": "20200513021720",
          "lateShipDate": "20200513021720",
          "orderMethod": "P",
          "deliverToDockBuilding": "H",
          "deliverToDockArea": "H",
          "deliverToBuilding": "H",
          "deliverToArea": "07D",
          "deliverToCoordinates": "H07DBR1702",
          "deliverToDropZoneBuilding": "HZ",
          "deliverToDropZoneArea": "HZ",
          "jitCallNumber": "1234",
          "kanbanNumber": "1234",
          "startOnLineDate": "20200513021720",
          "buildDate": "20200513021720",
          "transactionNumber": "1234101"
        }
      ]
    }
  ]
}
[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": "&"
      }
    }
  }
]

提前感谢....

共有1个答案

荆修明
2023-03-14

低于规范作品,

对于OrderHeader,将所有节点转移到OrderHeader,然后从其结果中移除OrderDetails

[
  {
    "operation": "shift",
    "spec": {
      "OrderDetail": {
        "@1": "OrderInfo[#1].OrderHeader",
        "@": "OrderInfo[#1].OrderDetail"
      }
    }
  }, {
    "operation": "remove",
    "spec": {
      "OrderInfo": {
        "*": {
          "OrderHeader": {
            "OrderDetail": ""
          }
        }
      }
    }
  }
]
 类似资料:
  • 有人能帮我定义jolt规范,把输入json转换成输出json吗..我在一个文件中输入了json,像{"filename":"test1 "," value":"10"} {"filename":"test2 "," value":"10"}。转换后的输出json应该如下所示:{"filename":"test "," overallvalue":"20 "," filename":[{"filen

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

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

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

  • 我正在尝试使用JOLT转换从JSON数组中移除一个字段。下面是输入JSON和预期输出JSON。< br >您能为提到的场景建议JOLT转换吗 输入JSON 预期输出

  • 我有以下格式的json(不限于像本例中那样的两个文档,可能有很多、更多): 我想从本质上将多种此类json文档“非规范化”为一个json文档,如下所示: 还想添加类似的东西 应转化为: 到目前为止,我对Jolt的有限理解使我相信这种转换是可能的,但从所提供的文档中还不清楚如何进行这种转换。任何有关Jolt规范的帮助都将不胜感激!!