Jolt Transform - 将 ID 字段和数组索引分配到深层嵌套数组中

Jolt Transform - Distribute ID field and array index into deeply nested array

我有如下所示的深层嵌套数据。数据可能看起来没有必要嵌套,但我删除了不重要的数据以减少一些混乱。

[
  {
    "id": "1",
    "entries": [
      {
        "data": {
          "values": [
            {
              "data_of_interest": {
                "frames": [
                  {
                    "filename": "arg",
                    "module": "bar",
                    "package": "foo",
                    "platform": "blargh"
                  },
                  {
                    "filename": "arg1",
                    "module": "barge",
                    "package": "something",
                    "platform": "blargh.io"
                  }
                ]
              }
            }
          ]
        }
      }
    ]
  },
  {
    "id": "2",
    "entries": [
      {
        "data": {
          "values": [
            {
              "data_of_interest": {
                "frames": [
                  {
                    "filename": "app",
                    "module": null,
                    "package": null,
                    "platform": null
                  }
                ]
              }
            }
          ]
        }
      }
    ]
  }
]

我要做的是将 'id' 字段分配到 'frames' 数组中的每个记录中,以及每个帧的索引,然后将所有帧展平到一个列表中.结果数据如下所示:

[
  {
    "id": 1,
    "frame_idx": 0,
    "filename": "arg",
    "module": "bar",
    "package": "foo",
    "platform": "blargh"
  },
  {
    "id": 1,
    "frame_idx": 1,
    "filename": "arg1",
    "module": "barge",
    "package": "something",
    "platform": "blargh.io"
  },
  {
    "id": 2,
    "frame_idx": 0,
    "filename": "app",
    "module": null,
    "package": null,
    "platform": null
  }
]

我这辈子都想不出如何将 id 或索引正确分配到帧记录中。我的尝试总是将 id 和 index 放在旁边,但不在框架记录内。

首先深入到最内层(level of indexes of the "frames" list)。然后,确定公共因素(@(9,id))以便将结果嵌套在公共数组下,同时用[&1]分隔比如

[
  {
    "operation": "shift",
    "spec": {
      "*": { // top level indexes
        "entries": {
          "*": { //indexes of "entries"
            "*": { // "data"
              "*": { // "values"
                "*": { // indexes of "values"
                  "*": { // "data_of_interest"
                    "*": { // "frames"
                      "*": { // indexes of "frames"                                                
                        "@(8,id)": "@(9,id).[&1].id", // go 8 or 9 levels up respectively in order to grab the value of "id"
                        "$": "@(9,id).[&1].frame_idx",
                        "*": "@(9,id).[&1].&"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": ""
      }
    }
  }
]

站点http://jolt-demo.appspot.com上的演示