0

Am new to nifi(1.14) and using JOLTTransform processor to transfer the input json (flatten) to nested json. I could not able to fix with the JOLT Schema. kindly help me on this.

The input JSON is :

[
  {
    "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"
  }
]

and the expected JSON output is

{
  "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"
      }
    }
  }
}

Thanks in Advance.

1 Answer 1

1

You can use successive shift transformations; enumarate the keys of the objects within the first one, and then rename them while nesting each under the related keys such as

[
  {
    "operation": "shift",
    "spec": {
      "*": "&"
    }
  },
  {
    "operation": "shift",
    "spec": {
      "0": "Trading.Source",
      "*": "Trading.Destination.@(0,tableName)"
    }
  }
]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.