You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用Jolt将JSON中runtime的时分秒格式转为整数秒数

Jolt转换实现时分秒格式runtime转秒数及字段映射

以下是满足需求的Jolt转换规范,可同时完成runtime的秒数转换、caption的布尔值转换以及其他字段的平级映射:

[
  {
    "operation": "shift",
    "spec": {
      "title_info": {
        "titleId": "titleId",
        "contentType": "contentType",
        "caption": {
          "Yes": "caption"
        },
        "runtime": "runtime"
      }
    }
  },
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "caption": "=toBoolean",
      "runtime": "=intSum(@(1,runtime).split(':')[0]*3600, @(1,runtime).split(':')[1]*60, @(1,runtime).split(':')[2])"
    }
  }
]

转换逻辑说明:

  1. Shift操作:将title_info下的指定字段提取到根节点,同时对caption做初步映射,指定"Yes"对应目标字段。
  2. Modify操作:
    • caption:通过=toBoolean内置函数将字符串"Yes"转换为布尔值true。
    • runtime:先通过split(':')将时分秒格式的字符串分割为数组,分别取出小时、分钟、秒对应的元素,按小时*3600 + 分钟*60 + 秒的公式计算总秒数,最后通过intSum转为整数类型。

输入示例:

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

输出结果:

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

内容的提问来源于stack exchange,提问作者user1111880

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.19 03:09:56