Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Jolt Transformer to match key array with value arrays

I have a json input object, and want to do a json transformation using jolt transformer. can help to acheive this

Input is

{
  "keys": [
    "key1",
    "key2",
    "key3"
  ],
  "values": [
    [
      "value 1.1",
      "value 2.1",
      "value 3.1"
    ],
    [
      "value 1.2",
      "value 2.2",
      "value 3.2"
    ]
  ]
}

and the expected output is

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

{
  "Result": [
    {
      "key1": "value 1.1",
      "key2": "value 2.1",
      "key3": "value 3.1"
    },
    {
      "key1": "value 1.2",
      "key2": "value 2.2",
      "key3": "value 3.2"
    }
  ]
}

>Solution :

You can loop hrough values array while picking the values from the keys after traversing 3 levels such that

[
  {
    "operation": "shift",
    "spec": {
      "values": {
        "*": {
          "*": "Result[&1].@(3,keys[&])"// &1 represents the outer indexes under "values" node 
                                        // &  is for the inner indexes
        }
      }
    }
  }
]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading