将 unnest 列表摇晃到顶层

Jolt unnest list to top level

我有一个 JSON:

[
  {
    "id": 1015380,
    "type": "campaign",
    "stats": [
      {
        "message_sends_by_any_user": 13,
        "ctr": "0.094",
      }
    ]
  },
  {
    "id": 1015695,
    "type": "campaign",
    "stats": [
      {
        "message_sends_by_any_user": 7,
        "ctr": "0.091",
      }
    ]
  }
]

我想“取消嵌套”stats 列表到顶层。震动配置:

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "id": "[&1].id",
        "type": "[&1].type",
        "stats": {
          "*": "[&2].&"
        }
      }
    }
  }
]

预计:

[
  {
    "id": 1015380,
    "type": "campaign",
    "message_sends_by_any_user": 13,
    "ctr": "0.094",
  },
  {
    "id": 1015695,
    "type": "campaign",
    "message_sends_by_any_user": 7,
    "ctr": "0.091"
  }
]

但实际输出包含这样的数组索引:

[ 
 {
   "id" : 1015380,
   "type" : "campaign",
   "0" : {
           "message_sends_by_any_user" : 13,
           "ctr" : "0.094"
         }, ...

如何避免这些索引?

您可以选择 id 和 [= 遍历 stats 列表的索引23=]type里面的属性如

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "stats": {
          "*": {
            "@(2,id)": "[&3].id",
            "@(2,type)": "[&3].type",
            "*": "[&3].&"
          }
        }
      }
    }
  }
]

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