1
votes

I need to use jolt transform to do the below JSON transformation.

need to create new columns from the list from reeval column where sometimes we only one value and some times we get multiple values my input data :-

example 1:

{
  "id":"1",
  "reeval":["one","two"]
}

example 2:

{
  "id":"2",
  "reeval":["one","two","three"]
}

example 3:

{
  "id":"3",
  "reeval":["one"]
}

I have written jolt expresson as below

[
   {
     "operation": "shift",
     "spec": {
       "id": "id",
       "reeval": {
         "*": "&"
       }
     }
  }
]

with above jolt expression is working fine but unable to add column name output for above jolt is as below

example 1:

{
  "id" : "1",
  "0" : "one",
  "1" : "two"
}

example 2:

{
  "id" : "2",
  "0" : "one",
  "1" : "two",
  "2" : "three"
}

here i am unable to change the names of the columns as i need to change colunms as below my expected output after jolt transformation should be like

example 1:

{
  "id":"1",
  "reeval":"one",
  "reeval1":"two"
}

example 2:

{
  "id":"2",
  "reeval":"one",
  "reeval1":"two",
  "reeval2":"three"
}

example 3:

{
  "id":"3",
  "reeval":"one"
}
1

1 Answers

0
votes

Prepending &1 to the current ampersand would suffice in order to go one level up the tree, and to grab the key name in the first shift transformation, and then apply another to rename only the key with index zero such as

[
  {
    "operation": "shift",
    "spec": {
      "id": "id",
      "reeval": {
        "*": "&1&"
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "reeval0": "reeval",
      "*": "&"
    }
  }
]