Search code examples
jsonapache-nifijolt

Jolt: split/ concat array values in Nifi


I'm struggling with transformation using JOLT in Nifi

My input

[
  {
    "value0": 0,
    "value1": 1,
    "value2": 2
  },
  {
    "value0": 3,
    "value1": 4,
    "value2": 5
  }
]

Desired Output:

[
  {
    "val": 0
  },
  {
    "val": 1
  },
  {
    "val": 2
  },
  {
    "val": 3
  },
  {
    "val": 4
  },
  {
    "val": 5
  }
]

I almost managed to get it to work. Here is my (wrong) Jolt Spec:

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "value*": "[&1].val"
      }
    }
  }
]

Here is my result:

[
  {
    "val": [ 0, 1, 2 ]
  },
  {
    "val":[ 3, 4, 5 ]
  }
]

Thanks!


Solution

  • Try this,

    [
      {
        "operation": "shift",
        "spec": {
          "*": {
            "value*": "[].val"
          }
        }
    }]