jsonapache-nifijolt

How to concatenate two attributes in a Jolt transform


I have below input in JSON format :

{
  "firstName": "Scott",
  "lastName": "Parker"
}

I need the output in the following structure :

{
  "data": {
    "fullName": "Scott Parker"
  }
}

I really don't understand how should work jolt transform processor in nifi

Maybe there are any alternatives in nifi ?

Thanx a lot!!


Solution

  • The example in Jagadesh's link is a good one, the =concat function does exactly what you want (even the field names are the same). Then you just need a shift spec to move the fullName field into the data field and ignore the rest:

    [
      {
        "operation": "modify-default-beta",
        "spec": {
          // String join the values in the array x, with a comma and a space
          "fullName": "=concat(@(1,firstName),' ',@(1,lastName))"
        }
      },
      {
        "operation": "shift",
        "spec": {
          "fullName": "data.fullName"
        }
      }
    ]