如何使用Jolt to json数组来嵌套json?

dy1byipe  于 2023-03-24  发布在  其他
关注(0)|答案(1)|浏览(107)

我是nifi(1.14)的新手,使用JOLTTransform处理器将输入的json(flatten)转换为嵌套的json。我无法用JOLT Schema修复。请帮助我。
输入的JSON是:

[
  {
    "executionTime": "2244",
    "processorId": "3ef03f9c-b42c-4c4e-9d5f-d14878bb2c84",
    "filename": "Trading",
    "processStartTime": "2021-07-26 16:31:19",
    "processSQL": "TradingDetails.sql",
    "executionFetchTime": "2049",
    "sourceCountValue": "5076",
    "startTime": "1627297279651",
    "processGroupName": "Trading"
  },
  {
    "ProcessEndTime": "2021-07-26 16:31:29",
    "completedTime": "1627297289412",
    "processDuration": "0",
    "destCountValue": "5076",
    "tableName": "TRADINGDETAILS"
  },
  {
    "ProcessEndTime": "2021-07-26 16:31:29",
    "completedTime": "1627297289412",
    "processDuration": "0",
    "destCountValue": "5076",
    "tableName": "CUSTTRADINGDETAILS"
  }
]

预期的JSON输出为

{
  "Trading": {
    "Source": {
      "executionTime": "2244",
      "processorId": "3ef03f9c-b42c-4c4e-9d5f-d14878bb2c84",
      "filename": "Trading",
      "processStartTime": "2021-07-26 16:31:19",
      "processSQL": "TradingDetails.sql",
      "executionFetchTime": "2049",
      "sourceCountValue": "5076",
      "startTime": "1627297279651",
      "processGroupName": "Trading"
    },
    "Destination": {
      "TRADINGDETAILS": {
        "ProcessEndTime": "2021-07-26 16:31:29",
        "completedTime": "1627297289412",
        "processDuration": "10",
        "destCountValue": "5076",
        "tableName": "TRADINGDETAILS"
      },
      "CUSTTRADINGDETAILS": {
        "ProcessEndTime": "2021-07-26 16:31:29",
        "completedTime": "1627297289412",
        "processDuration": "10",
        "destCountValue": "5076",
        "tableName": "CUSTTRADINGDETAILS"
      }
    }
  }
}

先谢了。

4sup72z8

4sup72z81#

可以使用连续的shift转换;枚举第一个对象中对象的键,然后重命名它们,同时将每个对象嵌套在相关键下,如

[
  {
    "operation": "shift",
    "spec": {
      "*": "&"
    }
  },
  {
    "operation": "shift",
    "spec": {
      "0": "Trading.Source",
      "*": "Trading.Destination.@(0,tableName)"
    }
  }
]

相关问题