0
votes

Here's my input data :

[

{ "TEST1": "abcd", "TEST2": "xyz", "TEST3": "08" }, { "TEST1": "abcd", "TEST2": "xyz", "TEST3": "20" } ]

Output

[

{ "TEST1": "root", "TEST2": "xyz", "TEST3": ["08","20"] }

]

Expected Output

[

{ "TEST1": "abcd", "TEST2": "xyz", "TEST3": ["08","20"] }

]

Jolt specs

[ { "operation": "shift", "spec": { "": { "TEST3": "@(1,TEST2).TEST3" } } }, { "operation": "shift", "spec": { "": { "$1": "[#2].TEST1", "$": "[#2].TEST2", "@.TEST3": "[#2].TEST3" } } }

]

Can you please help me in achieving the excpected output

1

1 Answers

0
votes

Check this spec

[
  //Concat the TEST1 and TEST2 to temp
  {
    "operation": "modify-default-beta",
    "spec": {
      "*": {
        "temp": "=concat(@(1,TEST1),':',@(1,TEST2))"
      }
    }
 },
  //Group the values by shifting TEST3
  {
    "operation": "shift",
    "spec": {
      "*": {
        "TEST3": "@(1,temp)"
      }
    }
 },
  // Assign the keys to the node named key and value to the node nameed value
  {
    "operation": "shift",
    "spec": {
      "*": {
        "@": "[#2].key",
        "$": "[#2].value"
      }
    }
  },
  //Shift and assign the respective values to the TEST1, TEST2 and TEST3
  {
    "operation": "shift",
    "spec": {
      "*": {
        "value": {
          "*:*": {
            "$(0,1)": "[&3].TEST1",
            "$(0,2)": "[&3].TEST2"
          }
        },
        "key": "[&1].TEST3"
      }
    }
  }


]