JOLT Transformation Merge Array of multi Objects

I am trying to create a jolt transformation for the below input;

{
  "group": [
    {
      "schema": "file"
    },
    {
      "key1": "val1",
      "key2": "val2"
    },
    {
      "schema": "folder"
    },
    {
      "key1": "val1",
      "key2": "val2"
    },
    {
      "schema": "dir"
    },
    {
      "key1": "val1",
      "key2": "val2"
    },
    .....more
  ]
}

With the desired output of;

{
  "group": [
  {
    "schema": "file",
    "key1": "val1",
    "key2": "val2"
  },
  {
    "schema": "folder",
    "key1": "val1",
    "key2": "val2"
  },
  {
    "schema": "dir",
    "key1": "val1",
    "key2": "val2"
  },
  .....more
]
}

The key 'schema' will always be present but I won't know what the key1,key2,etc values are. So I can't explicitly map them. Any help would be much appreciated!


Solution 1:

You can use successive shift transformations such as

[
//to get three independent arrays with key names : `schema`, `key1`, `key2`
//nested within an object named `group`
  {
    "operation": "shift",
    "spec": {
      "group": {
        "*": {
          "*": "&2.&"
        }
      }
    }
  },
//dissipate each key-value pairs due to corresponding positions of each element 
//within each array 
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": {
          "*": "&2[&].&1"
        }
      }
    }
  }
]

enter image description here