无法使用 JOLT 转换将数组中的一组字段转换为各个单独的数组

问题描述

输入:

{
  "chain": [
    {
      "formation": [
        {
          "itemID": "1111","isConsiderable": false
        },{
          "itemID": "2222","isConsiderable": false
        }
      ]
    },{
      "formation": [
        {
          "itemID": "3333",{
          "itemID": "4444","isConsiderable": false
        }
      ]
    }
  ]
}

震动规格:

    [
  {
    "operation": "shift","spec": {
      "chain": {
        "*": {
          "formation": {
            "*": {
              "itemID": "productsList[&1].products"
            }
          }
        }
      }
    }
}
]

当前输出

    {
  "productsList" : [ {
    "products" : [ "1111","3333" ]
  },{
    "products" : [ "2222","4444" ]
  } ]
}

期望的输出

  {
    "productsList" : [ {
    "products" : [ "1111","2222" ]
          },{
    "products" : [ "3333","4444" ]
     } ]
   }

我想匹配每个编队数组的 itemID 并将它们分组到相应的数组中。 通过使用 jolt 转换,我可以对 products 数组进行分组,但不能按照所需的格式对各个数组的 itemID 进行分组,但在这里对输入 json 中所有数组的相同索引上发生的字段进行分组。

提前致谢

解决方法

在您的规范中,&1 是指存储在 formation 键下的数组中的索引。您需要在链数组 (&3) 中指定索引,然后在 formation 数组中指定索引 - 如下面的规范所示:

[
  {
    "operation": "shift","spec": {
      "chain": {
        "*": {
          "formation": {
            "*": {
              "itemID": "productsList[&3].products[&1]"
            }
          }
        }
      }
    }
}
]