簡體   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