bazaarvoice / jolt

JSON to JSON transformation library written in Java.
Apache License 2.0
1.56k stars 329 forks source link

Not able to convert array of values as comma separated value #937

Open prakashvenkat22 opened 4 years ago

prakashvenkat22 commented 4 years ago

I am trying to convert array of values as comma separated value in jolt, but I am not able get output as comma separated value. Input

{
  "errors": [
    {
      "code": 100,
      "message": [
        "msg1",
        "msg2"
      ]
    },
    {
      "code": 101,
      "message": [
        "msg1"
      ]
    },
    {
      "code": 102,
      "message": [
        "msg1",
        "msg2",
        "msg3"
      ]
    }
  ]
}

Jolt Spec I have tried

  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "errors": {
        "*": {
          "*": "=concat(@0)"
        }
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "errors": {
        "*": {
          "code": "errors[].code",
          "message": "errors[&1].message"
        }
      }
    }
  }
]

Output as

{
  "errors": [
    {
      "code": 100,
      "message": "msg1msg2"
    },
    {
      "code": 101,
      "message": "msg1"
    },
    {
      "code": 102,
      "message": "msg1msg2msg3"
    }
  ]
}

desired output as

{
  "errors": [
    {
      "code": 100,
      "message": "msg1,msg2"
    },
    {
      "code": 101,
      "message": "msg1"
    },
    {
      "code": 102,
      "message": "msg1,msg2,msg3"
    }
  ]
}
zeshuai007 commented 4 years ago

Hi @prakashvenkat22 You should use join instead of concat. E.g: =join(',',@0)