'JOLT transform data create nested pairs

I am trying to convert the following

[
  {
    "PLCTime": "1643804542000",
    "LevelID": "53.99.2",
    "Data1Type": "Axis1 Dist",
    "Data1": "1.0",
    "Data2Type": "Axis2 Dist",
    "Data2": "2.0",
    "Data3Type": "Axis3 Dist",
    "Data3": "3.0",
    "Data4Type": "Axis4 Dist",
    "Data4": "4.0",
    "Data5Type": "Axis5 Dist",
    "Data5": "5.5",
    "Data6Type": "Axis6 Dist",
    "Data6": "6.0"
/// etc 20 data points
  }
]

to achive this as desired output

{
  "assetId": "53.99.2",
  "dataPoints": [
    {
      "timestamp": "1643804542000",
      "measures": [
        {
          "name": "Axis1 Dist",
          "value": 1
        },
        {
          "name": "Axis2 Dist",
          "value": 2
        }
      ]
    }
  ]
}

Where the LevelID becomes "assetID" and PLCTime becomes "timestamp"

So far I have for a spec:

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "LevelID": "LevelID",
        "*": "dataPoints."
      }
    }
  },
  {
    "operation": "sort",
    "spec": {
      "*": ""
    }
  }
]

which brings the level ID to the top level and gives me and array of data points but from here I am struggling to create pairs from the data below.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source