【问题标题】:Jolt Transformation: How to shift some values into each map in list颠簸变换:如何将一些值转移到列表中的每个地图中
【发布时间】:2019-08-09 02:40:13
【问题描述】:

我从昨天开始一直在进行 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}
]

我可以将“年”、“月”、“日”的值作为列表插入到每个地图之外,例如 {"record":[[2019,8,9],{map1},{map2}]} ,但这不是我想要的。

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

【问题讨论】:

    标签: arrays json dictionary transform jolt


    【解决方案1】:

    这应该做你想做的:

    解决方案(内嵌说明):

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多