Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

NiFi - JOLT assign value to attribute from Json Array

Solved Go to solution
Highlighted

NiFi - JOLT assign value to attribute from Json Array

New Contributor

Json Input:

[
{
"BRANCH_CODE": "7Z3",
"CUST_AC_NO": "Z256VM3K6872CY1F8",
"AC_DESC": "437T7F97CET",
"CUST_NO": "RX1"
},
{
"BRANCH_CODE": "7Z3",
"CUST_AC_NO": "Z256VM3K6872CY1F8",
"AC_DESC": "437T7F97CET",
"CUST_NO": "RX1"
}
]

 

Expected Output:

[ {
"ExternalSystemIdentifier" : "Z256VM3K6872CY1F8",
"Fields" : {
"FLD0001" : "7Z3",
"FLD0002" : "RX1",
"FLD0003" : "437T7F97CET"
},
"InstitutionId" : "1"
}, {
"ExternalSystemIdentifier" : "Z256VM3K6872CY1F8",
"Fields" : {
"FLD0001" : "7Z3",
"FLD0002" : "RX1",
"FLD0003" : "437T7F97CET"
},
"InstitutionId" : "1"
} ]

 

Jolt Spec:

[
{
"operation": "shift",
"spec": {
"*": {
"BRANCH_CODE": "[&1].FLD0001",
"CUST_NO": "[&1].FLD0002",
"AC_DESC": "[&1].FLD0003"
}
}
},
{
"operation": "shift",
"spec": {
"*": {
"$": "[#2].ExternalSystemIdentifier",
"@": "[#2].Fields"
}
}
},
{
"operation": "default",
"spec": {
"*": {
"InstitutionId": "1"
}
}
}

]

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted

Re: NiFi - JOLT assign value to attribute from Json Array

Super Guru

You can refer to the "Fields" output field explicitly instead of needing another shift:

 

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "CUST_AC_NO": "[&1].ExternalSystemIdentifier",
        "BRANCH_CODE": "[&1].Fields.FLD0001",
        "CUST_NO": "[&1].Fields.FLD0002",
        "AC_DESC": "[&1].Fields.FLD0003"
      }
    }
},
  {
    "operation": "default",
    "spec": {
      "*": {
        "InstitutionId": "1"
      }
    }
  }
]

View solution in original post

2 REPLIES 2
Highlighted

Re: NiFi - JOLT assign value to attribute from Json Array

Super Guru

You can refer to the "Fields" output field explicitly instead of needing another shift:

 

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "CUST_AC_NO": "[&1].ExternalSystemIdentifier",
        "BRANCH_CODE": "[&1].Fields.FLD0001",
        "CUST_NO": "[&1].Fields.FLD0002",
        "AC_DESC": "[&1].Fields.FLD0003"
      }
    }
},
  {
    "operation": "default",
    "spec": {
      "*": {
        "InstitutionId": "1"
      }
    }
  }
]

View solution in original post

Highlighted

Re: NiFi - JOLT assign value to attribute from Json Array

New Contributor

Thanks Alot @mburgess 

Don't have an account?
Coming from Hortonworks? Activate your account here