Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

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!