颠簸变换:如何将一些值转移到列表中的每个地图中

Jolt Transformation: How to shift some values into each map in list

我从昨天开始一直在做 Jolt 转换,但找不到实现以下输出的解决方案。
我想将 "year"、"month"、"day" 插入到 "records" 列表的每个地图(字典)中。

输入

[{"root":
   {"body":
    {"year":2019,
     "month":8,
     "day":9,
     "records":[
       {"user":"a",
        "item":"x",
        "price":300,
        "count":1},
       {"user":"b",
        "item":"y",
        "price":100,
        "count":3}]
     }
   }
}]

期望输出

[{"user":"a",
  "item":"x",
  "price":300,
  "count":1,
  "year":2019,
  "month":8,
  "day":9},
  {"user":"b",
   "item":"y",
   "price":100,
   "count":3,
   "year":2019,
   "month":8,
   "day":9}
]

我可以将 "year"、"month"、"day" 的值作为 {"record":[[2019,8,9] 这样的列表插入到每个地图的外部,{map1},{map2}]},但这不是我想要的。

感谢您提供任何帮助或建议。提前谢谢你。

这应该可以满足您的要求:

解决方案(内联解释):

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "root": {
          "body": {
            "records": {
              //match records array
              "*": {
                //copy object user, item etc. to current position
                "@": "[&1]",
                //go up two levels and get year and place it in current array position
                "@(2,year)": "[&1].year",
                "@(2,month)": "[&1].month",
                "@(2,day)": "[&1].day"
              }
            }
          }
        }
      }
    }
  }
]

输出:

[
  {
    "user": "a",
    "item": "x",
    "price": 300,
    "count": 1,
    "year": 2019,
    "month": 8,
    "day": 9
  },
  {
    "user": "b",
    "item": "y",
    "price": 100,
    "count": 3,
    "year": 2019,
    "month": 8,
    "day": 9
  }
]