如何使用 JOLT 转换将顶级对象移动到数组 属性

How can I move top level object to array property using JOLT transformation

有没有办法在具有顶级对象值的数组项中添加额外的 属性? 我的输入就像

{
  "ABC": {
    "news": [{
        "datetime": "2019-03-06T14:12:00-05:00",
        "source": "source 1",
        "summary": "asd ada dsd f ef sdf vert"
      }
    ]
  },
  "XYZ": {
    "news": [{
        "datetime": "2019-03-06T14:12:00-05:00",
        "source": "source 1",
        "summary": "asd ada dsd f ef sdf vert"
      }
    ]
  }
}

预期输出为

"news": [{
    "symbol": "ABC",
    "datetime": "2019-03-06T14:12:00-05:00",
    "source": "source 1",
    "summary": "asd ada dsd f ef sdf vert"
  },
  {
    "symbol": "XYZ",
    "datetime": "2019-03-06T14:12:00-05:00",
    "source": "source 1",
    "summary": "asd ada dsd f ef sdf vert"
  }
]

通过使用下面的规范,我可以合并两个数组,但我很难在项目中添加符号。

[{
  "operation": "shift",
  "spec": {
    "*": {
      "news": {
        "*": ""
      }
    }
  }
}]

我设法使用 2 个轮班规则做到了。首先,我将符号名称提取到数组中并合并新闻列表,然后我将符号元素推入新闻项(使用正确的数组索引位置):

 [{
     "operation": "shift",
     "spec": {
       "*": {
         "$": "symbol",
         "news": {
           "*": "news"
         }
       }
     }
}, {
     "operation": "shift",
     "spec": {
       "news": {
         "*": {
           "@(3,symbol[&])": "news[&1].symbol",
           "*": "news[&1].&"
         }
       }
     }
}
 ]

看看这是否是您要找的。 干杯