JOLT - 根据键值对数组对象进行排序

JOLT - Sort array objects depending on keys values

我想根据 2 个键的特定值对数组的对象进行排序。特别是我想按特定的 kpiId 值排序,对于具有该 kpiId 值的对象,按 simulationId 值排序。这会迭代两次。

输入

{
  "kpiResults": [
    {
      "simulationId": 3939,
      "kpiId": 81,
      "startTime": "2022-01-05T10:20:47",
      "value": 2
    },
    {
      "simulationId": 3936,
      "kpiId": 80,
      "startTime": "2022-01-05T10:20:47",
      "value": 1
    },
    {
      "simulationId": 3940,
      "kpiId": 80,
      "startTime": "2022-01-05T10:20:47",
      "value": 12
    },
    {
      "simulationId": 3940,
      "kpiId": 81,
      "startTime": "2022-01-05T10:20:47",
      "value": 88
    },
    {
      "simulationId": 3937,
      "kpiId": 80,
      "startTime": "2022-01-05T10:20:47",
      "value": 32
    },
    {
      "simulationId": 3939,
      "kpiId": 80,
      "startTime": "2022-01-05T10:20:47",
      "value": 11
    },
    {
      "simulationId": 3938,
      "kpiId": 80,
      "startTime": "2022-01-05T10:20:47",
      "value": 12
    },
    {
      "simulationId": 3938,
      "kpiId": 81,
      "startTime": "2022-01-05T10:20:47",
      "value": 6
    },
    {
      "simulationId": 3936,
      "kpiId": 81,
      "startTime": "2022-01-05T10:20:47",
      "value": 4
    },
    {
      "simulationId": 3937,
      "kpiId": 81,
      "startTime": "2022-01-05T10:20:47",
      "value": 21
    }
  ]
}

所需输出(按 kpiId=80simulationId 排序,然后按 kpiId=81[=24= 排序],simulationId)

{
  "kpiResults": [
    {
      "simulationId": 3936,
      "kpiId": 80,
      "startTime": "2022-01-05T10:20:47",
      "value": 1
    },
    {
      "simulationId": 3937,
      "kpiId": 80,
      "startTime": "2022-01-05T10:20:47",
      "value": 32
    },
    {
      "simulationId": 3938,
      "kpiId": 80,
      "startTime": "2022-01-05T10:20:47",
      "value": 12
    },
    {
      "simulationId": 3939,
      "kpiId": 80,
      "startTime": "2022-01-05T10:20:47",
      "value": 11
    },
    {
      "simulationId": 3940,
      "kpiId": 80,
      "startTime": "2022-01-05T10:20:47",
      "value": 12
    },
    {
      "simulationId": 3936,
      "kpiId": 81,
      "startTime": "2022-01-05T10:20:47",
      "value": 4
    },
    {
      "simulationId": 3937,
      "kpiId": 81,
      "startTime": "2022-01-05T10:20:47",
      "value": 21
    },
    {
      "simulationId": 3938,
      "kpiId": 81,
      "startTime": "2022-01-05T10:20:47",
      "value": 6
    },
    {
      "simulationId": 3939,
      "kpiId": 81,
      "startTime": "2022-01-05T10:20:47",
      "value": 2
    },
    {
      "simulationId": 3940,
      "kpiId": 81,
      "startTime": "2022-01-05T10:20:47",
      "value": 88
    }
  ]
}

对于所需的 JOLT 规范的任何帮助,我们将不胜感激。 干杯 M

您可以在组合 kpiIdsimulationId 值对象键名后应用 排序 转换,然后删除它们:

[
  {
    "operation": "shift",
    "spec": {
      "kpiResults": {
        "*": "@(0,kpiId).@(0,simulationId)"
      }
    }
  },
  {
    "operation": "sort"
  },
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": "kpiResults"
      }
    }
  }
]