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

编写Jolt Transformation遇阻,求符合要求的转换规则

问题:Jolt转换无法生成外层videos数组及合并subtitle/caption到textTracks

输入JSON

{
  "templateLanguage": "FREEMARKER",
  "outputFormat": "JSON",
  "templateName": "MPX",
  "data": {
    "DSID": "36455-001",
    "media": {
      "subtitle": [
        {
          "fileName": "Tiger_s_Apprentice_The_caption_5005141918_202401030424.vtt",
          "filePath": "ingest/viacom/paramountdvhdrsdr/8100132118",
          "materialSubType": "Feature",
          "locale": "es-419"
        }
      ],
      "caption": [
        {
          "fileName": "Tiger_s_Apprentice_The_36455_001_FTR_CCAP_T3092_Closed_Caption_SCC_2398_engCC_5005136914_202401030425.scc",
          "filePath": "ingest/viacom/paramountdvhdrsdr/8100132118",
          "materialSubType": "Feature",
          "locale": "en-US"
        }
      ],
      "audio": [
        {
          "fileName": "Tiger_s_Apprentice_The_36455_001_FTR_AOUTPUT_A4970_Audio_BWF_2398_5_1_Interleaved_engAU_5005143352.wav",
          "channels": "6",
          "filePath": "ingest/viacom/paramountdvhdrsdr/8100132118",
          "materialSubType": "Feature",
          "locale": "en-US",
          "type": "5.1 Surround"
        },
        {
          "dvs": true,
          "fileName": "Tiger_s_Apprentice_The_36455_001_FTR_AOUTPUT_A4964_Audio_BWF_2398_2_0_Interleaved_engAU_5005143913.wav",
          "channels": "2",
          "filePath": "ingest/viacom/paramountdvhdrsdr/8100132118",
          "materialSubType": "Feature",
          "locale": "en-US",
          "type": "2.0 Stereo (L/R)"
        }
      ]
    }
  }
}

期望输出JSON

{
  "videos": [
    {
      "textTracks": [
        {
          "techSpec": {
            "type": "subtitle",
            "locale": "es-419",
            "filePath": "ingest/viacom/paramountdvhdrsdr/8100132118"
          },
          "fileName": "Tiger_s_Apprentice_The_caption_5005141918_202401030424.vtt"
        },
        {
          "techSpec": {
            "type": "caption",
            "locale": "en-US",
            "filePath": "ingest/viacom/paramountdvhdrsdr/8100132118"
          },
          "fileName": "Tiger_s_Apprentice_The_36455_001_FTR_CCAP_T3092_Closed_Caption_SCC_2398_engCC_5005136914_202401030425.scc"
        }
      ],
      "audios": [
        {
          "fileName": "Tiger_s_Apprentice_The_36455_001_FTR_AOUTPUT_A4970_Audio_BWF_2398_5_1_Interleaved_engAU_5005143352.wav",
          "techSpec": {
            "locale": "en-US",
            "filePath": "ingest/viacom/paramountdvhdrsdr/8100132118",
            "materialSubType": "Feature",
            "type": "5.1 Surround"
          }
        },
        {
          "fileName": "Tiger_s_Apprentice_The_36455_001_FTR_AOUTPUT_A4964_Audio_BWF_2398_2_0_Interleaved_engAU_5005143913.wav",
          "techSpec": {
            "locale": "en-US",
            "dvs": true,
            "filePath": "ingest/viacom/paramountdvhdrsdr/8100132118",
            "materialSubType": "Feature",
            "type": "2.0 Stereo (L/R)"
          }
        }
      ],
      "mediaMetadata": [
        {
          "fileName": "Tiger_s_Apprentice_The_36455_001_FTR_DOC_Document_Color_Spec_16x9LB_engPT_5005134061.xml",
          "techSpec": {
            "filePath": "ingest/viacom/paramountdvhdrsdr/8100132118"
          }
        }
      ]
    }
  ]
}

尝试的Jolt Spec

[
  {
    "operation": "shift",
    "spec": {
      "data": {
        "media": {
          "thumbnail": {
            "*": {
              "fileName": "images[&1].fileName",
              "filePath": "images[&1].techSpec.filePath"
            }
          },
          "subtitle": {
            "*": {
              "fileName": "textTracks[&1].fileName",
              "#subtitle": "textTracks[&1].techSpec.type",
              "locale": "textTracks[&1].techSpec.locale",
              "filePath": "textTracks[&1].techSpec.filePath"
            }
          },
          "caption": {
            "*": {
              "fileName": "textTracks[&2].fileName",
              "#caption": "textTracks[&2].techSpec.type",
              "locale": "textTracks[&2].techSpec.locale",
              "filePath": "textTracks[&2].techSpec.filePath"
            }
          }
        }
      }
    }
  }
]

解决方案

正确的Jolt Spec

[
  {
    "operation": "shift",
    "spec": {
      "data": {
        "media": {
          "subtitle": {
            "*": {
              "fileName": "videos[0].textTracks[].fileName",
              "#subtitle": "videos[0].textTracks[&1].techSpec.type",
              "locale": "videos[0].textTracks[&1].techSpec.locale",
              "filePath": "videos[0].textTracks[&1].techSpec.filePath"
            }
          },
          "caption": {
            "*": {
              "fileName": "videos[0].textTracks[].fileName",
              "#caption": "videos[0].textTracks[&1].techSpec.type",
              "locale": "videos[0].textTracks[&1].techSpec.locale",
              "filePath": "videos[0].textTracks[&1].techSpec.filePath"
            }
          },
          "audio": {
            "*": {
              "fileName": "videos[0].audios[&1].fileName",
              "locale": "videos[0].audios[&1].techSpec.locale",
              "dvs": "videos[0].audios[&1].techSpec.dvs",
              "filePath": "videos[0].audios[&1].techSpec.filePath",
              "materialSubType": "videos[0].audios[&1].techSpec.materialSubType",
              "type": "videos[0].audios[&1].techSpec.type"
            }
          }
        }
      }
    }
  },
  {
    "operation": "default",
    "spec": {
      "videos": [
        {
          "mediaMetadata": []
        }
      ]
    }
  }
]

关键调整说明

  1. 构建外层videos数组:通过videos[0]将所有内容嵌套到单元素的videos数组中,匹配输出结构。
  2. 合并subtitle和caption到textTracks:使用textTracks[]的语法,让两个数组的元素自动追加到同一个textTracks数组里,无需手动指定索引,Jolt会按顺序合并。
  3. audio字段映射:将audio下的对应字段按要求放到audios数组的techSpec对象中,保留所有需要的属性。
  4. 默认mediaMetadata数组:通过default操作,在输入没有mediaMetadata字段时生成空数组,和输出结构对齐(如果输入存在该字段,可在shift操作中添加对应映射规则)。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.30 20:22:07