json - 如何检查 Azure 数据工厂中的值是否为 null

标签 json azure azure-data-factory

我正在尝试使用 Azure 数据工厂来运行 API 调用。这是我在将数据传递给 API 调用之前从 SQL 数据库获取的数据:

 {
    "document_send_date": "2023-06-26T00:00:00Z",
    "onboarding_form_send_date": null
}

有时这些值看起来像第一项。有时,该值为空。对于此 API 调用,我需要使用“yyyy-MM-dd”日期格式。我尝试使用 formatDateTime() 如下:

@concat('{
    "data": [
        {
            "document_send_date": "', formatDateTime(item().document_send_date, 'yyyy-MM-dd'), '",
            "onboarding_form_send_date": "', formatDateTime(item().onboarding_form_send_date, 'yyyy-MM-dd'), '"
        }
    ]
}')

将日期时间值转换为日期值。但是,当值为 null 时,formatDateTime() 函数将返回错误。有没有办法检查传递给 formatDateTime() 的值是否为 null,如果是,则返回“null”,如果不是,则返回传递给函数的日期时间的日期字符串?

最佳答案

您可以使用if(condition,exp1,exp2)函数来检查该值是否为空。

像下面这样改变你的表情:

@concat('{
    "data": [
        {
            "document_send_date": "', if(not(equals(item().document_send_date,null)),formatDateTime(item().document_send_date, 'yyyy-MM-dd'),item().document_send_date),'",',
            '"onboarding_form_send_date": "', if(not(equals(item().onboarding_form_send_date,null)),formatDateTime(item().onboarding_form_send_date, 'yyyy-MM-dd'),item().onboarding_form_send_date),'"
        }
    ]
}')
  • 这里,上面的表达式检查空值。如果这些不为空,则给出日期,否则将采用空值。
  • 当我们处理字符串时,上面的表达式会将 null 转换为 JSON 中的空字符串。如果需要,您可以在其他情况下根据您的要求更改字符串。

在这里,为了以 JSON 格式显示输出,我使用 ForEach 内的附加事件将上述结果 JSON 附加到数组中,并在上述表达式周围使用 json()

enter image description here

结果:

enter image description here

关于json - 如何检查 Azure 数据工厂中的值是否为 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76559150/

相关文章:

java - Spring Boot ArrayList/JSON : add all Elements of a certain type to a list of this type

azure - 是否可以在不离线的情况下将 ASP.NET Core 网站部署到 Azure?

json - 如何在 Azure Data Lake Analytics 上下文中分别使用 JSON 文件格式 usql

azure - 构建 Cosmos DB 的哈希 token 签名

azure - ADF 复制事件中的更新插入选项

azure-data-factory - ADF 管道和 ADF 数据流有什么区别?

json - Swift 中解析 json 值并获取 ID 到 var 中

arrays - symfony 渲染 json_array 实体类型并使用表单保存

c# - Restsharp:反序列化具有比某些类更少/更多字段的 json 对象

parameters - 使用 SQL 查询的 Azure 数据工厂设置参数