bazaarvoice / jolt

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

jolt transformation to concatenate two elements of json array #1174

Open araval6969 opened 1 year ago

araval6969 commented 1 year ago

Could any one please help with jolt transformation of following type of operation?

json array: [ { "firstName": "Fname1", "lastName": "Lname1", "state": "PA" }, { "firstName": "Fname2", "lastName": "Lname2", "state": "VA" }, { "firstName": "Fname3", "lastName": "Lname3", "state": "CA" } ]

expected output:

{ names:["Fname1 Lname1", "Fname2 Lname2","Fname3 Lname3"] states:["PA","VA","CA"] }

charlesardsilva commented 1 year ago

Hi @araval6969 You can use this to solve it:

[
  {
    "operation": "modify-default-beta",
    "spec": {
      "*": {
        "fullName": "=concat(@(1,firstName),' ',@(1,lastName))"
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": {
        "fullName": "names",
        "state": "states"
      }
    }
  }
]