Skip to content
Advertisement

Jolt Transformation Spec for array of arrays [closed]

I hava a json input and expected output is below. please help me in generating the spec.

Input JSON:

{  
    "Features": [    
      "fields": [
        {
          "name": "featureName"
        },
        {
          "name": "featureVersion"
        },
        {
          "name": "featureLevel"
        },
        {
          "name": "featureComponent"
        }
      ],
      "rows": [
        [
          "checkoutandopeninnative",
          "11R1",
          "1.0.0",
          "CheckoutAndOpenInNative",
          "1.0"
        ],
        [
          "ConfigurationMigration",
          "1.0",
          "1.0.1.68",
          "ConfigMigrationUtility",
          "1.0"
        ]
      ]
    ]    
}

Expected Output JSON:

 {
      "Features": [
        {
          "featureName": "checkoutandopeninnative",
          "featureVersion": "11R1",
          "featureLevel": "1.0.0",
          "featureComponent": "CheckoutAndOpenInNative"
        },
        {
          "featureName": "ConfigurationMigration",
          "featureVersion": "1.0",
          "featureLevel": "1.0.1.68",
          "featureComponent": "ConfigMigrationUtility"
        }
      ]
}

please help me with the spec to convert it in jolt. Am very new to jolt and few tried didnt work.

Thanks, Hari

Advertisement

Answer

This spec should work for you:

[
  {
    "operation": "shift",
    "spec": {
      "Features": {
        "rows": {
          "*": {
            "*": "Features[&1].@(3,fields[&].name)"
          }
        }
      }
    }
  }
]

Notes:

  • I assume your input should look more like: "Features" : { ... } not "Features": [] as pointed out by @Franta
  • Checkout the https://jolt-demo.appspot.com/ where you can find the examples of the operators used in the snippet above
  • Also checkout the shiftr docs where you can find more info about the *, & and @ operators and their advanced versions

To make it easier to understand while reading the docs: shift operation explanation

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement