1

I am trying to transform the data from a multi array to single array using jolt technique. But unable to do so. Below are the details.

Input file:

{
  "oi": [
    {
      "ei": [
        {
          "type": "bs",
          "id": "797416713"
        }
      ]
    },
    {
      "ei": [
        {
          "type": "bs",
          "id": "797416716"
        }
      ]
    }
  ]
}

Jolt file used is as below:

[
 {
    "operation": "shift",
    "spec": {
      "oi": {
        "*": {
          "ei": {
            "*": {
              "type": {
                "bs": {
                  "@(2,id)": "oi[#3].bs"
                }
              }
            }
          }
        }
      }
    }
  }
]

Expected output from above is as below.

{
  "oi": [
    {
      "bs": [
        "797416713",
        "797416716"
      ]
    }
  ]
}

Actual output coming from jolt is :

{
  "oi": [
    {
      "bs": [
        "797416713",
        "797416716"
      ]
    }
  ]
}
Barbaros Özhan
  • 59,113
  • 10
  • 31
  • 55
Atul Gupta
  • 11
  • 1
  • Hello @Atul Gupta and welcome to StackOverflow. I believe this answer might help you : [How do I transform an array using Jolt?](https://stackoverflow.com/questions/37865871/how-do-i-transform-an-array-using-jolt). Please format the title so it is a question (researchable, clear problem). and provide [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example). You may also want to add the programming language you are using in tags, along with the file format. update tags: "arrays" is unlikely to find experts for your question. Java, Json, Jolt, is better – Florian Fasmeyer Jan 27 '23 at 01:16
  • Does this answer your question? [How do I transform an array using Jolt?](https://stackoverflow.com/questions/37865871/how-do-i-transform-an-array-using-jolt) – Remi Cuingnet Jan 27 '23 at 12:47
  • Hi Atul, welcome to SO. I couldn't see a difference between the actual and the expected output. Can you please edit the expected to fix it. – Barbaros Özhan Jan 27 '23 at 13:07

1 Answers1

0

Currently the desired and actual output values are identical. I understand from the expression

to transform the data from a multi array to single array

that you need to get such a result of type array of objects tagged current inner(ei) and outer(oi) keys such as(if not please clearly state) :

[
  {
    "oi": {
      "ei": [
        {
          "type": "bs",
          "id": "797416713"
        },
        {
          "type": "bs",
          "id": "797416716"
        }
      ]
    }
  }
]

Then, you can use this shift transformation spec :

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": {
          "*": {
            "*": {
              "@": "[#2].&4.&2"
            }
          }
        }
      }
    }
  }
]

where &4 will grab the key oi after going 4 levels up, &2 will grab the key ei after going 2 levels up the tree

Barbaros Özhan
  • 59,113
  • 10
  • 31
  • 55