Search code examples
apache-nifijolt

JOLT - Join nested arrays


I'm trying to join (comma separated) a nested array but cannot achieve it.

Input:

{
    "PARTS" : [ [ "aaaa", "bbbb" ], [ "cccc", "dddd" ] ]
}

Desired output:

{
    "PARTS": [ "aaaa,bbbb", "cccc,dddd" ]
}

I am trying to use =join but yet unsuccessful. Any help is appreciated.

Thanks!


Solution

  • I managed to get the output you were aiming for :)

    [
      {
        "operation": "modify-overwrite-beta",
        "spec": {
          "PARTS": {
            "*": "=join(', ',@0)"
          }
        }
      }
    ]
    

    The trick here is using @0, which points to the 0-th element on the hierarchy you're working with. At least, that's what the documentation says.