2

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 Answer 1

4

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.