json JOLT仅在不为NULL时连接

ia2d9nvy  于 2023-03-04  发布在  其他
关注(0)|答案(2)|浏览(96)

只有当year的值不为空时,我才需要将日期从YEAR更改为固定的YYYY-MM-DD
现在我有这个

[
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "Passing?": "=concat(@(1,Passing),-01-01'"
    }
  }
]
    • 输入:**
{
  "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-01-01",
  "Comments": "NotMentioned",
  "Team": "2",
  "modified_date": "2023-01-27 13:41:39",
  "Profile": "DM",
  "JobRole": "Tester"
}

如果没有年份,我需要保持"Passing"等于"null"。

vyswwuz2

vyswwuz21#

Passing属性的后缀**?运算符针对存在性** checkout ,而不是针对*可空性*** checkout 。
您可以在
modify转换规范中使用isNull**函数来检查条件,例如

[
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "Passing": ["=isNull", "=concat(@(1,&),'-01-01')"]// the value is overwritten provided the Passing has a non-null value
    }
  }
]

其中**@(1,&)**复制属性Passing的当前值

icnyk63a

icnyk63a2#

我不知道你的Passing值是什么,如果它不是null,但你可以使用下面的规格,如果你想实现你想要的输出.
质量标准:

[
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "Passing": "=concat(@(1,Passing),'-01-01')"
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": "&",
      "Passing": {
        "-*": {
          "@": "&2"
        },
        "*": {
          "@1": "&2"
        }
      }
    }
  }
]

如果Passing为空,则得到**null
如果Passing等于2023,则得到
2023-01-01**

相关问题