1
votes

I have an Array of Jsons and I want to transform the keys of individual Jsons while still maintaining the Array.

[
  {
    "a": "1",
    "b": "2"
  },
  {
    "a": "one",
    "b": "two"
  }
]

Desired output:

[
  {
    "my_a": "1",
    "my_b": "2"
  },
  {
    "my_a": "one",
    "my_b": "two"
  }
]

JOLT Spec:

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "a": "my_a",
        "b": "my_b"
      }
    }
  }
]

However, I see this:

{
  "my_a" : [ "1", "one" ],
  "my_b" : [ "2", "two" ]
}

I see that the transformation is applied but the output is not what I expect.

Anyone who has faced similar problems?

1

1 Answers

3
votes

You need to include array index [&1] while changing the name

Try with below Jolt Spec:

[
  {
    "operation": "shift",
    "spec": {
      "*": { 
        "a": "[&1].my_a",
        "b": "[&1].my_b"
      }
    }
  }
]

Validating the Spec:

enter image description here