Our Community is getting an upgrade! To get everything ready for the relaunch, we’ll be placing the site in read-only mode starting September 21st.
We really appreciate your understanding while we get things set up behind the scenes. Catch up on all the exciting details about the move here.
Need help or have questions? Drop us a line at [email protected]

Support Questions

Find answers, ask questions, and share your expertise
Announcements
Share your experience with Cloudera on G2 and get a $25 Amazon Gift card.
Hi, I'm CLEO! Something exciting is coming to the Community. Stay Tuned!

NiFi - JOLT assign value to attribute from Json Array

avatar
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

avatar
Master 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

3 REPLIES 3

avatar
Master 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"
      }
    }
  }
]

avatar
New Contributor

Thanks Alot @mburgess 

avatar
Expert Contributor

Hi @Ayaz , @mburgess !

Please have a look at this spec as well!

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

 Just FYI!