How to transform data using Jolt spec in nifi

dash

I want this data to be transformed in a given way using the jolt spec of Nifi.

Conditions are if studentId and loc_id are the same then we will combine their info and will pass the rest as it is. There are empty fields as well "".

Data

[
  {
    "studentId": "2222",
    "loc_id": "L1",
    "topId": "Lotus",
    "SubID1": "A1",
    "SubID2": "B1"
  },
  {
    "studentId": "2222",
    "loc_id": "L1",
    "topId": "tulip",
    "SubID1": "A2",
    "SubID2": ""
  },
  {
    "studentId": "3333",
    "loc_id": "L3",
    "topId": "Rose",
    "SubID1": "A3",
    "SubID2": ""
  },
  {
    "studentId": "4444",
    "loc_id": "L3",
    "topId": "Rose",
    "SubID1": "A5",
    "SubID2": "B7"
  }
]

Data after jolt spec: First two data have same studentId and loc_id so we have combined their info and rest two have passed as it is with an addition of visit list

[
  {
    "studentId": "2222",
    "loc_id": "L1",
    "VisitList": [
      {
        "topId": "Lotus",
        "SubID1": "A1",
        "SubID2": "B1"
      },
      {
        "topId": "tulip",
        "SubID1": "A2",
        "SubID2": ""
      }
    ]
  },
  {
    "studentId": "3333",
    "loc_id": "L1",
    "VisitList": [
      {
        "topId": "Rose",
        "SubID1": "A3",
        "SubID2": ""
      }
    ]
  },
  {
    "providerId": "4444",
    "specillity": "L3",
    "VisitList": [
      {
        "topId": "Rose",
        "SubID1": "A5",
        "SubID2": "B7"
      }
    ]
  }
]
Mohammadreza Khedri

You can use this spec:

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "@": "@(1,studentId).@(1,loc_id)"
      }
    }
  },
  {
    "operation": "cardinality",
    "spec": {
      "*": {
        "*": "MANY"
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": {
          "*": {
            "studentId": "[#4].&",
            "loc_id": "[#4].&",
            "topId|SubID*": "[#4].VisitList[&1].&"
          }
        }
      }
    }
  },
  {
    "operation": "cardinality",
    "spec": {
      "*": {
        "studentId": "ONE",
        "loc_id": "ONE"
      }
    }
  }
]

1 - shift: You should create a unique root for every object. In this case, we create it by combining 2 values like this: @(1,studentId).@(1,loc_id).

2 - cardinality: change every object that has 1 object to an array. We should do this to prepare our input for the next shift operation.

3 - shift: create your desired output.

4 - cardinality: change studentId and loc_id to a string in all objects.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Nifi Jolt Transform Spec

Nifi Jolt Transform Spec - Rename value

How to consider null values in jolt spec in NIFI?

JOLT spec for nifi processor

Jolt Spec for Nifi

Merge Json arrays using Jolt transform in NIFI

Jolt Transform JSON Spec

Jolt transform spec

Convert the array values into json object using Jolt Transform in Apache NiFi

Jolt transform to put the json content in a field using NiFi

How do I write a jolt transform spec to iterate through a loop?

Jolt Transform Producing Arrays in NiFi

Jolt transform to flatten a array in Nifi

How do i transform a nested json to Jolt in Apache NIFI

How to compare two lists having json in a single large list and map it using common column key in NiFi using jolt transform

I need to transform a JSON into Key Value SON using jolt spec. What should be the right spec to do it?

How do I transform an array using Jolt?

How to transform Json to Json using Jolt Specification?

How to transform a JSON using JOLT format

Using Jolt Spec how to reverse reduce a list of dictionary by a key using

Jolt Transform JSON Spec map with dynamic values

Jolt Transform JSON Spec with Unknown keys

Jolt Transform JSON Spec for Array Input

Spec Expression for JOLT transform of Json Array

Jolt Transform JSON Spec for List JSON Input

NiFi Jolt transform list of string to Map

How to append constant array to another array using Jolt spec transformation

How to insert json object in nested json using Jolt Spec

JSON attribute value split by space and put them into new attributes using Jolt transform Apache nifi

TOP Ranking

HotTag

Archive