HimalayanCoder
HimalayanCoder

Reputation: 9850

Convert an Array to Comma separated String in JOLT

I am trying to convert an array to comma separated string using jolt transform. Is there a way to achieve this ?

{
    "scores": [
        "a",
        "b",
        "c",
        "d",
        "e"
    ]
}

Expected Output

{
    "scores": "a,b,c,d,e"
}

Upvotes: 1

Views: 1695

Answers (2)

Mohammadreza Khedri
Mohammadreza Khedri

Reputation: 2691

You can use join with modify-overwrite-beta operation.

[
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "scores": "=join(', ',@(1,scores))"
    }
  }
]

enter image description here

Upvotes: 1

Dhruva kumar.R
Dhruva kumar.R

Reputation: 11

you can try the following spec

[{ "operation": "modify-overwrite-beta",

"spec": { "scores":"=concat(@(2,scores[0]),',',@(2,scores[1]),',',@(2,scores[2]),',',@(2,scores[3]),',',@(2,scores[4]))" } }

]

Upvotes: 1

Related Questions