0

I have JSON data coming thru external application A where which need to be sent to application B . And before the data goes to application B, all the attributes in the json need to be renamed.

for example , incoming json data structure is -

{
  "Array1": [
    {
      "field1": "foo1",
      "field2": [
        "bar1",
        "bar2"
      ]
    },
    {
      "field1": "foo2",
      "field2": [
        "bar3",
        "bar4"
      ],

      ...

        {
      "field1": "fooN",
      "field2": [
        "barX",
        "barY"
      ] 

    }
  ]
}

Where number of elements in Array1 are variable per record.

The expected output is -

{
  "ElementList": [
    {
      "Attr1": "foo1",
      "Attr2": [
        "bar1",
        "bar2"
      ]
    },
    {
      "Attr1": "foo2",
      "Attr2": [
        "bar3",
        "bar4"
      ],

      ...

        {
      "Attr1": "fooN",
      "Attr2": [
        "barX",
        "barY"
      ]  

    }
  ]
}

Basically

  • Array1 renamed to ElementList
  • each Field1 in Array1 renamed to Attr1
  • each Field2 Array1 renamed to Attr2

For simple rename, I can use shift operator but I am not able to specify correct jolt transformation for arrays. Any ideas?

Vendetta
  • 2,078
  • 3
  • 13
  • 31
Pushkr
  • 3,591
  • 18
  • 31
  • 1
    related: https://stackoverflow.com/questions/39585360/rename-fields-in-nested-arrays-using-jolt-transformation – joehinkle11 Oct 23 '19 at 17:12

1 Answers1

0

Chect if this suits you:

[
  {
    "operation": "shift",
    "spec": {
      "Array1": "ElementList"
    }
  },
  {
    "operation": "shift",
    "spec": {
      "ElementList": {
        "*": {
          "field1": "ElementList[&1].Attr1",
          "field2": "ElementList[&1].Attr2"
        }
      }
    }
  }
]
Magda
  • 482
  • 4
  • 9
  • Thank you! Yup , that’s what I came up with based on related question the other user pointed out. – Pushkr Oct 29 '19 at 13:25