Search code examples
jsonjolt

How to retrieve all the values of RHS and putting it into an array using jolt transform


Input:

[
  {
    "name": "vedhh"
  },
  {
    "name": "guru"
  }
]

Expected Output:

{
  "Registered_Names" : [ "vedhh", "guru" ]
}

The spec I'm currently using now is mentioned below. It takes both keys and values and I want to only take a list of values and make it an array of strings. Spec:

[
  {
    "operation": "shift",
    "spec": {
      "*": "Registered_Names[]"
    }
  }
]

Solution

  • Just dive one level deeper in order only to extract the values, but not the key names so as to form the desired array such as

    [
      {
        "operation": "shift",
        "spec": {
          "*": {
            "*": "Registered_Names[]"
          }
        }
      }
    ]