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

如何在JOLT中仅当年份非空时拼接为YYYY-MM-DD格式

解决JOLT处理null字段时错误拼接字符串的问题

你当前的JOLT规则在Passing字段非空时能正常生成YYYY-MM-DD格式,但当字段值为null时,会错误地将null转为字符串拼接成null-01-01。要实现仅非空时拼接,null值保持原样,可以通过JOLT的条件判断函数修正规则:

修正后的JOLT规则

[
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "Passing": "=if(notNull(@(1,Passing)), concat(@(1,Passing), '-01-01'), @(1,Passing))"
    }
  }
]

规则说明

  • 使用=if函数做条件分支判断:
    1. 用notNull(@(1,Passing))检查字段是否非空
    2. 非空时执行concat(@(1,Passing), '-01-01')拼接日期格式
    3. 为空时直接返回原字段值@(1,Passing),保留null

测试示例

非空输入

{
  "Passing": "2022",
  "Comments": "NotMentioned",
  "Team": "2",
  "modified_date": "2023-01-27 13:41:39",
  "Profile": "DM",
  "JobRole": "Tester"
}

对应输出

{
  "Passing": "2022-01-01",
  "Comments": "NotMentioned",
  "Team": "2",
  "modified_date": "2023-01-27 13:41:39",
  "Profile": "DM",
  "JobRole": "Tester"
}

空值输入

{
  "Passing": null,
  "Comments": "NotMentioned",
  "Team": "2",
  "modified_date": "2023-01-27 13:41:39",
  "Profile": "DM",
  "JobRole": "Tester"
}

对应输出

{
  "Passing": null,
  "Comments": "NotMentioned",
  "Team": "2",
  "modified_date": "2023-01-27 13:41:39",
  "Profile": "DM",
  "JobRole": "Tester"
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.29 15:25:11