Search code examples
jsontextapache-nifijolt

Nifi - Separate the column in two colums (Array)


I have a JSON :

{
  "consultor_do_projeto": [
    "Iago de Oliveira",
    "Murilo Tavares"
  ]
}

I need to transform in:

{
  "consultor0" : "Iago de Oliveira",
  "consultor1" : "Murilo Tavares"
}

In Jolt Spec, Can I do this?

if the third item exists, it will be the consultor2

Thanks to help!


Solution

  • Yes, you can do through use of a Jolt spec such as

    [
      {
        "operation": "shift",
        "spec": {
          "*_do_projeto": {
            "*": {
              "@": "&(2,1)&"
            }
          }
        }
      }
    ]
    

    where

    • &(2,1) brings the 1st asterisk replacement from the 2 levels up (eg. the substring "consultor")

    and

    • & next to that brings the counterpart value for @ sign which refers the indexes (0,1,..) of the array.

    the demo on the site http://jolt-demo.appspot.com/ is

    enter image description here