Ask Your Question
2

How can I combine two rows without using an array by using JOLT transformation?

asked 2023-06-26 22:17:42 +0000

nofretete gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2023-06-26 22:42:02 +0000

djk gravatar image

Here is an example JOLT transformation that combines two rows without using an array:

Input:

{
  "id": "123",
  "name": "John",
  "age": "30"
},
{
  "id": "456",
  "name": "Jane",
  "age": "25"
}

JOLT transformation:

[
  {
    // Merge the two objects into one
    "operation": "shift",
    "spec": {
      "0": "&",
      "1": "&"
    }
  },
  {
    // Concatenate the id, name, and age values 
    "operation": "modify-overwrite-beta",
    "spec": {
      "id": "=concat(@(0,id),'_',@(1,id))",
      "name": "=concat(@(0,name),' ',@(1,name))",
      "age": "=concat(@(0,age),'_',@(1,age))"
    }
  },
  {
    // Remove the old id, name, and age keys
    "operation": "remove",
    "spec": {
      "0": {"id": "", "name": "", "age": ""},
      "1": {"id": "", "name": "", "age": ""}
    }
  }
]

Output:

{
  "id": "123_456",
  "name": "John Jane",
  "age": "30_25"
}

In this example, we use the "shift" operation to merge the two input objects into one. Then, we use the "modify-overwrite-beta" operation to concatenate the id, name, and age values from each object into a single value. Finally, we remove the old id, name, and age keys using the "remove" operation.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-06-26 22:17:42 +0000

Seen: 11 times

Last updated: Jun 26 '23