David Segovia
David Segovia

Reputation: 91

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!

Upvotes: 1

Views: 77

Answers (1)

vikepic
vikepic

Reputation: 61

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.

Upvotes: 1

Related Questions