Json转换使用Jolt将小时转换为秒

bybem2ql  于 2023-06-25  发布在  其他
关注(0)|答案(1)|浏览(152)

我输入了json,其中"runtime": "01:45:23"字段应该使用Jolt转换为secondsInteger)。还有其他领域的变化,以及需要和那些完成,但我坚持与运行时的转换
输入JSON:

{
  "title_info": {
    "titleId": "3518864",
    "contentType": "Episode",
    "titleBrief": "Beirut S1: 04",
    "runtime": "01:45:23",
    "caption": "Yes"
  }
}

输出:

{
  "titleId": "3518864",
  "contentType": "Episode",
  "caption": true,
  "runtime": 6323
}
sbtkgmzw

sbtkgmzw1#

Jolt中没有乘法函数,但是你可以在modify规范中使用***divide***,比如

[
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "title_info": {
        "t": "=split(':',@(1,runtime))",
        //"min_": "@(1,time_portions)",
        "time_portions": "=toInteger(@(1,t))",
        "rate0": "=divide(1,3600)",
        "rate1": "=divide(1,60)",
        "tp0_": "@(1,time_portions[0])",
        "tp0": "=divide(@(1,tp0_),@(1,rate0))",
        "tp1_": "@(1,time_portions[1])",
        "tp1": "=divide(@(1,tp1_),@(1,rate1))",
        "tp2": "@(1,time_portions[2])",
        "runtime": "=intSum(@(1,tp0),@(1,tp1),@(1,tp2))"
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": {
        "titleId|c*|runtime": "&"
      }
    }
  }
]

相关问题