繁体   English   中英

摇动转换:如何将一些值移入列表中的每个映射

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

从昨天开始,我一直在进行Jolt转换,但是找不到解决方案来实现以下输出。
我想在“记录”列表的每个地图(词典)中插入“年”,“月”,“天”。

输入

[{"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
  }
]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM